我正在尝试将用户输入的每个字符串分配给字符串数组。整个事情都在一个for
循环中,并由数组的索引进行评估。我的代码是:
String skillAssign[] = new String[100];
for (int i=0; isDone == false; i++)
{
System.out.println(skillAssign[i]);
System.out.println(i);
skillAssign[i] = keyboard.nextLine();
if ((!(skillAssign[i].equalsIgnoreCase("stats"))) && (!(skillAssign[i].equalsIgnoreCase("done"))))
{
assignmentValue = keyboard.nextInt();
if (((skillAssign[i].equalsIgnoreCase("health"))) && (skillPoints - assignmentValue >=0))
{
System.out.println("Added " + assignmentValue + " points to Health!");
skillPoints = (skillPoints - assignmentValue);
newMaxHealth = (assignmentValue + newMaxHealth);
}
//code that evaluates the string located inside the skillAssign[i] for other stats
}
第一个字符串计算正确,但是当我输入第二个字符串时,我得到 java.util.InputMisMatchException。我怎样才能得到它,以便它为用户输入的数组的每个索引分配一个字符串,然后评估它?(我想我得到了评估部分)
我试图将帖子限制为相关代码,因此省略了 isDone 之类的内容,但是当done
键入时 isDone 更改为 true 并且构造键盘时Scanner keyboard = new Scanner
所有其他变量都设置为 0,除了 SkillPoints