Info
This question is closed. Reopen it to edit or answer.
fixing errors in code
1 view (last 30 days)
Show older comments
class FindNearObj{
public static void main(String[] args) {
int X[] = new int[]{485,48,65,466,47,426,27};
int Y[] = new int[]{485,46,465,46,447,46,427};
int total_req_out = 3;
int[] positions = new int[total_req_out];
int[] req_x = new int[total_req_out];
int[] req_y = new int[total_req_out];
positions = find(X,Y,total_req_out);
//print(positions);
for(int i =0;i<total_req_out;i++){
int index = positions[i];
req_x[i] = X[index];
req_y[i] = Y[index];
}
//print(req_x);
//print(req_y);
}
public static int[] find(int[] X, int[] Y, int cnt)
{
int pos[] = new int[X.length];
double distance[] = new double[X.length];
for(int i=0;i<X.length;i++){
//double dis = find_distance(X[i],Y[i]);
//System.out.println(dis);
pos[i] = i;
distance[i] = find_distance(X[i],Y[i]);
}
for(int i =0;i<X.length;i++)
{
for(int j =i;j<X.length;j++)
{
if(distance[j]< distance[i])
{
double temp_dis = distance[i];
distance[i] = distance[j];
distance[j] = temp_dis;
int temp_pos = pos[i];
pos[i] = pos[j];
pos[j] = temp_pos;
}
}
}
//print(distance);
//print(pos);
return pos;
}
public static double find_distance(int x, int y){
return Math.sqrt((x-0)*(x-0) + (y-0)*(y-0));
}
public static void print(int[] pos){
for(int i =0;i<pos.length;i++)
System.out.print(pos[i]+" , ");
System.out.println();
}
public static void print(double[] distance){
for(int i =0;i<distance.length;i++)
System.out.print(distance[i]+" , ");
System.out.println();
}
}
hi can some one help me in fixing this erros in codes as i coundt understand the errors in it.
thanks
1 Comment
Rik
on 29 Oct 2019
This is a Matlab forum. For help on Java there are other forums. If you think this question is actally about Matlab, feel free to reopen the question and edit it to make clear how this relates to Matlab. Also, please use the tools explained on this page to make your question more readable.
Answers (0)
This question is closed.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!