Java 代码重复打印一行
顺便说一下,我输入了A。 你们有谁知道为什么会发生这种情况吗?你们可以试试这个:Java 代码重复打印一行,java,Java,顺便说一下,我输入了A。 你们有谁知道为什么会发生这种情况吗?你们可以试试这个: Please enter your course grade here: A Please enter your course grade here: Please enter your course grade here: A Please enter your course grade here: Please enter your course grade here: A Thank you! Keep up
Please enter your course grade here: A
Please enter your course grade here: Please enter your course grade here: A
Please enter your course grade here: Please enter your course grade here: A
Thank you! Keep up the good work!
char等级;
对于(int x=1;使用扫描仪获取输入…它将阻止序列,直到用户提供输入…这是给学校的,我的老师只希望我使用read和for循环。换行符与'a'
字符同时处理。因此,你的3个年级是'a'
,其他2个年级是'\n'
。如果您必须使用System.in.read();
,那么您的老师不知道如何从Java用户那里获取数据,所以无法修复它?非常感谢!
Please enter your course grade here: A
Please enter your course grade here: Please enter your course grade here: A
Please enter your course grade here: Please enter your course grade here: A
Thank you! Keep up the good work!
char grade;
for(int x=1; x<6; x++){
System.out.print("Please enter your course grade here: ");
grade = (char) System.in.read();
while (grade == '\n')
grade = (char) System.in.read();
}
System.out.println("Thank you! Keep up the good work!");
}