我已经用java编写了程序,程序应该找到最大数量的double类型,eclipse显示了一些错误。以下是代码
import java.util.Scanner;
public class MaxDouble {
public static void main (String[] args){
Scanner inp = new Scanner(System.in);
System.out.println ("Enter the three double numbers separated by spaces");
double d1 = inp.nextDouble();
double d2 = inp.nextDouble();
double d3 = inp.nextDouble();
double result = maximum (d1, d2, d3);
System.out.println ("Maximum is"+ result);
public static double maximum (double x, double y, double z)
{
double maxValue = x;
if (y > maxValue)
maxValue = y;
if (z > maxValue)
maxValue = z;
return maxValue;
}
}
}

答案 0 :(得分:0)
您应该将maximum
方法置于main
方法之外。
public class MaxDouble
{
public static void main (String[] args)
{
Scanner inp = new Scanner(System.in);
System.out.println ("Enter the three double numbers separated by spaces");
double d1 = inp.nextDouble();
double d2 = inp.nextDouble();
double d3 = inp.nextDouble();
double result = maximum (d1, d2, d3);
System.out.println ("Maximum is"+ result);
}
public static double maximum (double x, double y, double z)
{
double maxValue = x;
if (y > maxValue)
maxValue = y;
if (z > maxValue)
maxValue = z;
return maxValue;
}
}