我輸入了此java程序,計算Eclipse中的簡單興趣。我該如何解決此錯誤:結果無法解析爲變量
import java.util.Scanner;
public class PercentageCalculator
{
public static void main(String[] args)
{
double x = 0;
double y = 0;
Scanner scanner = new
Scanner(System.in);
System.out.println("Enter the value of x: ");
x = scanner.nextDouble();
System.out.println("Enter the value of y: ");
y = scanner.nextDouble();
System.out.println();
System.out.println("Calculating percentage: (x % of y): ");
System.out.println(x + " % of" + y + "is " + result);
System.out.println();
}
}
但是,當我試圖運行它,它給了我這個消息:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
result cannot be resolved to a variable
at PercentageCalculator.main(PercentageCalculator.java:19)
這是什麼意思?如何解決呢?
你需要聲明它,你不使用它,並使用谷歌第一 –
是'結果不能被解析爲一個變量' –
你忘了定義,計算並將**結果**賦值給*'result' *。 –