我一直在試圖創建一個程序,讓用戶輸入一些雞蛋來購買和計算價格。我曾嘗試使用掃描儀方法輸入整數,但我似乎無法導入掃描儀方法。無法導入java.util.Scanner
這是我有:
package eggsorder;
import java.util.Scanner;
import java.io.IOException;
public class EggsOrder {
static final double EGGS_DOZEN = 7.25;
static final double EGGS_SINGLE = 0.75;
static final int DOZEN_NUMBER = 12;
public static void main(String[] args) throws IOException {
System.out.println("Enter number of eggs for purchase: ");
Scanner enter = new Scanner(System.in);
int eggs = enter.nextInt();
System.out.println("You ordered " + eggs + "eggs.");
System.out.println("That is " + (eggs/DOZEN_NUMBER) + " dozen eggs at 7.25 per dozen and " + (eggs % DOZEN_NUMBER) + " additional eggs at 0.75 each");
System.out.println("Which is a total price of " + (((eggs % DOZEN_NUMBER) * EGGS_SINGLE) + ((eggs/DOZEN_NUMBER) * EGGS_DOZEN)));
這是運行後,我得到的錯誤:
java.lang.ExceptionInInitializerError
Caused by: java.lang.RuntimeException: Uncompilable source code - cannot find symbol
symbol: class Scanner
location: class java.util
at eggsorder.EggsOrder.<clinit>(EggsOrder.java:7)
代碼作品,未經掃描的方法,但它需要使用它。
我已經嘗試使用java.util和各種其他變化,但無濟於事。
此外,我使用NetBeans的最新版本和Java
你運行java程序的哪個工具? netbeans或eclipse? – sasikumar
你的源代碼中的其他地方是否有錯誤? import語句'import java.util.Scanner'是否給你一個錯誤? –
它可能有助於手動運行乾淨或清除所有緩存的文件 - 尤其是如果您的代碼在命令行中編譯得很好(您是否嘗試過?) – Hulk