Reputation: 3
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
Upvotes: 0
Views: 66
Reputation: 68715
You cannot nest methods in java so take distance
method out of main
method.
Upvotes: 3