布尔和方法

时间:2014-03-04 03:29:12

标签: java

我是编程新手,对于我的课程,我必须为以下内容编写方法和程序:

boolean allTheSame(double x, double y, double z)返回参数的平均值。

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;
        }


    }

}

鉴于我是新人,我该怎么做?

1 个答案:

答案 0 :(得分:1)

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

在调用方法之前,您无需放置boolean