java中双倍最大数计算程序出错

时间:2015-04-03 10:19:57

标签: java

我已经用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;
        	 }
         }
	
}




1 个答案:

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