我正在尝试将来自学生姓名和分数问题的用户输入转换为数组。我还需要帮助来打印数组。while 循环使用 boolean loopNaming 作为其条件,并且每次循环发生时都会更新 i 。
public static void main(String [] args)
{
Scanner keyboard = new Scanner(System.in);
double score;
boolean loopNaming=true;
int i=0;
String[] name = new String[i];
while(loopNaming==true)
{
System.out.printf("Enter name of student or done to finish: ");
name[i] = keyboard.next();
if(name[i].equals("done"))
{
loopNaming = false;
}
else
{
System.out.println("Enter score: ");
score = keyboard.nextDouble();
}
i=i+1;
}
System.out.println(name[i]);
}
}
饮歌长啸
繁华开满天机
慕妹3242003
相关分类