Java3.6检查输入
要求用户“输入数字:”4次。 如果输入的不是数字,请再次询问。 输入4个数字后,输出“成功”。 请使用while、if、if-else和do语句为我回答此代码Java3.6检查输入,java,integer,do-while,Java,Integer,Do While,要求用户“输入数字:”4次。 如果输入的不是数字,请再次询问。 输入4个数字后,输出“成功”。 请使用while、if、if-else和do语句为我回答此代码 int counter; System.out.print("Input a number: "); while(!(scan.hasNextInt()));{ for (int i = 0; i < 3; i++){ scan.next(); System.out.print(&qu
int counter; System.out.print("Input a number: ");
while(!(scan.hasNextInt()));{
for (int i = 0; i < 3; i++){
scan.next();
System.out.print("Input a number: ");
if (!(pass.equals(pass2))) {
counter++;
} else if (!(scan.hasNextInt())) {
}
}
if (counter >= 2) {
System.out.println("Input a number: ");
}
} else if (!(scan.hasNextInt())) { System.out.println("success."); }
int计数器;系统输出打印(“输入一个数字:”);
而(!(scan.hasnetint());{
对于(int i=0;i<3;i++){
scan.next();
系统输出打印(“输入一个数字:”);
如果(!(pass.equals(pass2)){
计数器++;
}否则如果(!(scan.hasNextInt())){
}
}
如果(计数器>=2){
System.out.println(“输入一个数字:”);
}
}如果(!(scan.hasnetint()){System.out.println(“成功”);}
这是非常基本的东西,但我正在努力数组来保存输入
int[] inputIntegers = new int[4]; // Array to save input
Scanner scan = new Scanner(System.in);
int counter = 0;
while(counter < 4) {
System.out.println("Input a number: ");
String input = scan.next();
if(input.matches("[-]?[0-9]*")){ // Checking, if input is an integer
inputIntegers[counter]=Integer.parseInt(input); // Persing string to integer
counter++;
} else {
System.out.println("Input is not an integer");
}
}
System.out.println("Success");
scan.close(); //Do not forget do close scanner
扫描仪扫描=新扫描仪(System.in);
int计数器=0;
while(计数器<4){
System.out.println(“输入一个数字:”);
字符串输入=scan.next();
if(input.matches(“[-]?[0-9]*”){//检查,如果输入是整数
inputIntegers[counter]=Integer.parseInt(输入);//将字符串转换为整数
计数器++;
}否则{
System.out.println(“输入不是整数”);
}
}
System.out.println(“成功”);
scan.close()//不要忘记关闭扫描仪
这是Java问题还是JavaScript问题?Java和JavaScript是完全不同的语言。此外,我们希望您尝试并在此处发布该尝试,而不仅仅是发布您的需求。显示一些代码。如果您没有自己的最小代码,我们将无法帮助您。int计数器;系统输出打印(“输入一个数字:”);而(!(scan.hasnetint());{for(inti=0;i<3;i++){scan.next();System.out.print(“输入一个数字:”);if(!(pass.equals(pass2)){counter++;}else if(!(scan.hasNextInt()){}if(counter>=2){System.out.println(“输入一个数字:);}else if(!(scan.hasNextInt())){System.out.println(“successful.”)}这是一个javascript问题,我相信我使用的是您展示的代码是Java。在您处理它之前,您必须知道您使用的是什么语言。