Info
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
fixing errors in code
조회 수: 1 (최근 30일)
이전 댓글 표시
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
Rik
2019년 10월 29일
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.
답변 (0개)
이 질문은 마감되었습니다.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!