[英]How do I fix this error: Result cannot be resolved to a variable
我輸入了這個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)
這是什么意思,我該如何解決?
聲明結果變量
double result = 0;
然后計算百分比並將其分配給結果變量。
result = your calculation;
然后打印
System.out.println(x + " % of" + y + "is " + result);
希望這會有所幫助:)
您尚未聲明結果變量
double result=0;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.