我是一名學生,剛學習類和方法。我收到一個錯誤(第30行 - 儲蓄= PR *折扣/ 100)「找不到符號」。我知道我的可變折扣超出了範圍,但我無法弄清楚如何解決這個問題。我已按照提供給我的說明進行操作,但仍然無法正常工作。我已經在課本中發現了一些錯別字,所以有什麼遺漏嗎?還是我對大括號的定位?Java變量超出範圍
import java.util.Scanner; // Allows for user input
public class ParadiseInfo2
{
public static void main(String[] args)
{
double price; // Variable for minimum price for discount
double discount; // Variable for discount rate
double savings; // Scanner object to use for keyboard input
Scanner keyboard = new Scanner(System.in);
System.out.print("Enter cutoff price for discount >> ");
price = keyboard.nextDouble();
System.out.print("Enter discount rate as a whole number >> ");
discount = keyboard.nextDouble();
displayInfo();
savings = computeDiscountInfo(price, discount);
System.out.println("Special this week on any service over " + price);
System.out.println("Discount of " + discount + " percent");
System.out.println("That's a savings of at least $" + savings);
}
public static double computeDiscountInfo(double pr, double dscnt)
{
double savings;
savings = pr * discount/100;
return savings;
}
public static void displayInfo()
{
System.out.println("Paradise Day Spa wants to pamper you.");
System.out.println("We will make you look good.");
}
}
這是一個簡單的問題來解決。我在下面添加了一個答案。 – Assafs
順便說一句,如果我的回答解決了這個問題 - 我可以問你笑納通過單擊旁邊的灰色複選標記的答案,使其成爲綠色? – Assafs
讓我們來看看爲什麼從變量名稱中刪除元音是一個糟糕的主意。 –