在嵌套循环中编译错误。

时间:2015-02-21 00:02:13

标签: java compiler-errors

当我尝试编译嵌套循环时,它给出了错误“非法启动表达式”。我写错了什么,我该如何解决这个问题。

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

1 个答案:

答案 0 :(得分:3)

你不能在java中嵌套方法,所以从distance方法中取出main方法。