0

When I try to compile the nested loop it gives me the error "illegal start of expression". what am I writing incorrectly and how can I fix this problem.

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
  • You have declared the method distance within the main method; move it outside of main Commented Feb 21, 2015 at 0:06

1 Answer 1

3

You cannot nest methods in java so take distance method out of main method.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.