[英]compile error in nested loop.
當我嘗試編譯嵌套循環時,出現錯誤“表達式的非法開始”。 我寫錯了什么以及如何解決此問題。
import java.util.Scanner;
public class Lab5a
{
public static void main(String args[])
{ //Problem here
public static double distance(double[]x, double[]y) //call distance method
{
double[] a = {1, 0, 0};
double[] b = {0, 1, 1};
double[] c = {1, 1, 1};
double[] d = {0, 0, 1};
{
double xy = Math.sqrt( //distance formula
(x[0]-y[0])*(x[0]-y[0]) +
(x[1]-y[1])*(x[1]-y[1]) +
(x[2]-y[1])*(x[2]-y[2]));
double ab = distance(a,b);
double ac = distance(a,d);
double ad = distance(a,c);
return xy;
}
System.out.println("ab=" + ab + ", ac=" + ac + ", ad=" + ad);
}
}//end main
}//end class
您不能在Java中嵌套方法,因此請從main
方法中移除distance
方法。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.