【发布时间】:2014-10-17 06:15:56
【问题描述】:
目标:
如果用户输入了一个非数字数字,让循环再次运行。 还有另一种(更有效的)编写数字输入的方法吗?
public static void user_input (){
int input;
input = fgetc (System.in);
while (input != '\n'){
System.out.println("Please enter a number: ");
if (input == '0' == '1' ..... '9'){
//Execute some code
}
else {
System.out.println("Error Please Try Again");
//Repeat While loop
}
}
}
编辑
我需要 while 循环条件。简单地问,你如何重复while循环?也没有扫描仪方法。
【问题讨论】:
-
Character.isDigit();将检查单个字符数。
标签: java loops if-statement while-loop numbers