我是一個新手Java學生,我需要根據他們的單位生產計算員工獎金。每當我運行該程序時,由於輸入而導致掃描儀錯誤。 「java.util.InputMismatchException」。任何幫助是極大的讚賞!Java輸入不匹配異常
/**
* NAME: Mitchell Noble
* DATE: October 27, 2015
* FILE: lab9
* COMMENTS: This java program is designed to caculate employee bonus's based on their units produced
*/
import java.util.Scanner;
public class lab9
{
public static void main(String[]args)
{
// declare variables
double Lastname;
double Currentunits;
double Lastunits;
double Firstname;
//Create a Scanner Object
Scanner keyboard= new Scanner(System.in);
//Get names and units
System.out.print("Hello we are going to learn about your production this year and award bonus's but first we need some information.");
System.out.print("What is your last name?");
Lastname = keyboard.nextDouble();
System.out.print("What is your first name?");
Firstname = keyboard.nextDouble();
System.out.print("How many units did you produce this year?");
Currentunits = keyboard.nextDouble();
System.out.print("How many units did you produce last year?");
Lastunits = keyboard.nextDouble();
//Sort into proper bonus category
if (Currentunits > Lastunits)
{
if (Currentunits >= 1000)
{
if (Currentunits >= 3001)
{
if (Currentunits >= 6001)
{
System.out.print(Firstname + Lastname + "Based on your units prodcued this year your bonus will be $200. Good work!");
}
else
{
System.out.print(Firstname + Lastname + "Based on your units prodcued this year your bonus will be $100. Good work!");
}
}
else
{
System.out.print(Firstname + Lastname + "Based on your units prodcued this year your bonus will be $50. Good work!");
}
}
else
{
System.out.print(Firstname + Lastname + "Based on your units produced this year your bonus will be $25. Good work!");
}
}
else
{
System.out.print(Firstname + Lastname + "Based on the units produced this year compared to last year you do not qualify for any bonu's.");
}
} // close main
} // close lab7
你試圖輸入一些內容不能被解析爲一個'double'控制檯。你能告訴我們你的意見嗎? –
你正在期待'lastName','firstName'這樣的值是'double'。檢查你的代碼。我想你必須使用'nextLine()'並將這些字段聲明爲字符串 – TheLostMind
爲什麼要將firstName和LastName聲明爲double而不是String? – kswaughs