我試圖拿兩個浮點值,看哪一個更大,並返回true或false。這是我的代碼:基本多類Java程序錯誤
import java.util.Scanner;
public class Four_Ten
{
public static void main(String []args){
double num1, num2 = 0;
Scanner scan = new Scanner(System.in);
System.out.println("Enter a floating point value:");
num1 = scan.nextFloat();
System.out.println("Enter another floating point value:");
num2 = scan.nextFloat();
System.out.println(calcGreater(num1, num2));
}
public double calcGreater(double a, double b){
boolean greater = false;
if (a > b){
greater = true;
}
if (b > a){
greater = false;
}
return greater;
}
}
我收到以下錯誤:
non-static method calcGreater(double, double) cannot be referenced from a static context
我該如何解決這個問題?
您認爲錯誤信息的含義是什麼? –
谷歌錯誤。你會找到解決方案。 –
閱讀Java中的'static'關鍵字.. –