質問
私の問題の原因は何であり、どのように解決すればよいですか?
ユーザーがdouble以外の値を入力すると、プログラムがクラッシュします。
プログラム本体
public class Annual
{
public static void main(String[] args)
{
Scanner percent = new Scanner(System.in);
System.out.println("Please enter annual sales:");
double yearly = percent.nextInt();
double T = 50000;
double Amt;
if (yearly.matches("[0-9]+") && yearly.length() > 2 && yearly.length() <= 8)
{
double YrPrcnt = yearly * .05;
Amt = T + YrPrcnt;
System.out.print("The Annual Payrate for employee is:");
System.out.print(Amt);
}
}
}
エラーメッセージ
「doubleは逆参照できません」および「不正な式の開始」
私が試したこと
最も簡単な方法:ユーザー入力が数字かどうかを確認し、数字の場合はエラーメッセージを表示します。
システム情報
私はこれをNetBeans7.2でコーディングしており、Javaは初めてです。