if (userOption == 2) {
System.out.println("You have chosen produce! Please enter (1) for organic or (0) for non-organic.");
type = sc.nextInt();
System.out.println("Please enter a name for this produce.");
name = sc.next();
sc.nextLine();
System.out.println("Please enter the amount of calories.");
calories = sc.nextInt();
System.out.println("Please enter the amount of carbohydrates.");
carbohydrates = sc.nextInt();
list.add(new Produce(name, calories, carbohydrates, type));
}
你好,當我把我的話之間的空間爲輸入「姓名」,它給了我一個錯誤InputMismatchError
的熱量時,即時通訊中的熱量沒有推杆,在用戶輸入「姓名」之前,卡路里甚至不應該得到輸入。謝謝:)代碼一直給人一種InputMismatchException時當我輸入2個字
你正在使用'sc.nextInt()'這是等待一個int,一個INTE ger不能包含空格,這是你的意思嗎? –
它期待一個int,而不是單詞。 – Stultuske
您預計卡路里是一個整數,而不是一個字符串 – TheLostMind