Я использую jcreator. В нем говорится, что процесс завершен, но когда вы переходите к переключению, то случай 4, затем выбирайте числа 1-9, он говорит, что java.numberformatexception. Что вызывает это и как я могу это исправить? Я просто новичок здесь.моя ошибка java.lang.NumberFormatException
import javax.swing.JOptionPane;
public class Exer29A {
public static String inputdialog(String s)
{
JOptionPane.showInputDialog(null,s);
return s;
}
static void messagedialog(String r)
{
JOptionPane.showMessageDialog(null, r);
}
public static void main(String[] args) {
int xx, x1, x2;
String n1, n2, LName, MName, FName;
FName = JOptionPane.showInputDialog(null, "What's your first name?");
MName = JOptionPane.showInputDialog(null, "What's your Middle name?");
LName = JOptionPane.showInputDialog(null, "What's your Last name?");
n2 = JOptionPane.showInputDialog(null, "So you are " + FName.substring(0,1).toUpperCase() + FName.substring(1).toLowerCase() + " " + MName.substring(0,1).toUpperCase() + MName.substring(1).toLowerCase() + " " + LName.substring(0,1).toUpperCase() + LName.substring(1).toLowerCase() + " " + "Do you wish to continue?[Y/N]");
if (n2.equalsIgnoreCase("Y"))
{
x1 = Integer.parseInt(JOptionPane.showInputDialog(null, "What do you want to do? \n 1. Add 2 integers \n 2. Area of a rectangle \n 3. Area of a triangle \n 4. Know your fate."));
switch (x1)
{
case 1:
{
x1 = Integer.parseInt(JOptionPane.showInputDialog(null, "Enter 1st integer."));
x2 = Integer.parseInt(JOptionPane.showInputDialog(null, "Enter 2nd integer"));
messagedialog("The sum of two numbers is " + (x1+x2));
}
break;
case 2:
{
x1 = Integer.parseInt(JOptionPane.showInputDialog(null, "Enter 1st integer."));
x2 = Integer.parseInt(JOptionPane.showInputDialog(null, "Enter 2nd integer"));
messagedialog("The area of the triangle is " + (x1*x2));
}
break;
case 3:
{
x1 = Integer.parseInt(JOptionPane.showInputDialog(null, "Enter base."));
x2 = Integer.parseInt(JOptionPane.showInputDialog(null, "Enter height"));
messagedialog("The are of the triangle is " + ((double)(0.5*x1*x2)));
}
case 4:
{
xx = Integer.parseInt(inputdialog("Choose numbers 1-9"));
{
if (xx==1)
messagedialog("You will be successful!");
else if (xx==2)
messagedialog("You will have a beautiful life. Blessings would come to you.");
else if (xx==3)
messagedialog("You are handsome/gorgeous. But.....");
else if (xx==4)
messagedialog("You must study well.");
else if (xx==5)
messagedialog("Unfortunately, you are unfortunate.");
else if (xx==6)
messagedialog("You will be an environmentalist. You will be called the Keeper of the Forest.");
else if (xx==7)
messagedialog("You are nothing but luck. You will be poured out with luck.");
else if (xx==8)
messagedialog("8. Nothing but a number. Try again.");
else
messagedialog("Endowed with the gift to serve others, people with the lucky number 9 are able to freely create an easy and relaxed atmosphere. /n Your humanity is welcomed among their friends. Besides, they are brilliant, funny, smart and generous. ");
}
}
break;
default:
messagedialog("invalid");
}
}
else if (n2.equalsIgnoreCase("N"))
System.exit(0);
else
messagedialog("INVALID");
}
}
Исключение StackTrace:
Exception in thread "main" java.lang.NumberFormatException: For input string: "Choose numbers 1-9"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:580)
at java.lang.Integer.parseInt(Integer.java:615)
at Exer29A.main(Exer29A.java:50)
И где происходит 'NumberFormatException'? – MadProgrammer
на корпусе выключателя # 4 – pcolor
Нет разрыва между № 3 и № 4, не уверен, что это преднамеренно. Каков ваш вклад в это условие? – MadProgrammer