我正在做班級的家庭作業(yè)。你得計算一下這個月的工資。每次我嘗試運(yùn)行它時,它都會不斷地說:我該如何解決這個問題?線程“main”中的異常 java.util.InputMismatchException在 java.util.Scanner.throwFor (Scanner.java:864)在 java.util.Scanner.next(Scanner.java:1485)在 java.util.Scanner.nextInt(Scanner.java:2117)在java.util.Scanner.nextInt(Scanner.java:2076)在 D2.main(D2.java:23)import java.util.Scanner;public class D2{ public static void main(String[] args) { Scanner sc = new Scanner(System.in); int L1Cs = 80; int L2Cs = 120; int L3Cs = 160; int L1Ct = 100; int L2Ct = 140; int L3Ct = 180; int L1Csv = 100; int L2Csv = 150; int L3Csv = 200; int BSalary = 3000; int Stotal, Ttotal, SVtotal; System.out.println("Please enter your name"); int name = sc.nextInt(); System.out.println("How many sedans have you sold this month"); int Sedans = sc.nextInt(); System.out.println("How many trucks have you sold this month"); int Trucks = sc.nextInt(); System.out.println("How many SUVs have you sold this month"); int SUVs = sc.nextInt(); if(Sedans <= 10) { Stotal = (L1Cs * Sedans); } else if (Sedans >= 11 && Sedans <=20) { Stotal = (L1Cs*10 +(Sedans - 10) * L2Cs); } else { Stotal = (L1Cs*10 +L1Cs *10 + (Sedans - 10) * L3Cs); } System.out.println("Your comission for the sedans is:" + Stotal); if(Trucks <= 10) { Ttotal = (L1Cs * Trucks); } else if (Trucks >= 11 && Trucks <=20) { Ttotal = (L1Ct*10 + (Trucks - 10) * L2Ct); } else { Ttotal = (L1Ct*10 + L2Ct *10 + (Trucks - 10) * L3Ct); }
1 回答

守著一只汪
TA貢獻(xiàn)1872條經(jīng)驗 獲得超4個贊
它似乎失敗的提示是:
"Please enter your name"
如果您輸入的是您的姓名而不是整數(shù),這就是它拋出異常的原因。掃描儀將尋找一個整數(shù),但你的名字不是。您可能想要替換:
int name = sc.nextInt();
和:
String name = sc.next();
或類似于將名稱獲取為字符串的內(nèi)容。
添加回答
舉報
0/150
提交
取消