I am new to programming and for my class I have to write a method and program for the following:

boolean allTheSame(double x, double y, double z) returning the average of the arguments.

public static void main(String[] args) {
    // **METHOD**//

    Scanner in = new Scanner(System.in);

    System.out.println("Enter variable for x");
    double x = in.nextDouble();

    System.out.println("Enter variable for y");
    double y = in.nextDouble();

    System.out.println("Enter variable for z");
    double z = in.nextDouble();

    boolean allTheSame = boolean allTheSame(x, y, z);
    System.out.println(allTheSame);

}

    // **TEST PROGRAM** //
 public static boolean allTheSame(double x, double y, double z)
 {

     if (x == y && x == z)
        {
            return true;
        }

     else
        {
            return false;
        }


    }

}

Given the fact that I am new, how can I do this?

有帮助吗?

解决方案

boolean allTheSame = allTheSame(x, y, z);
System.out.println(allTheSame);

You don't need to put boolean before you call the method.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top