嵌套循环中的编译错误。

compile error in nested loop.

当我尝试编译嵌套循环时,出现错误 "illegal start of expression"。我写错了什么,我该如何解决这个问题。

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 方法。