ages= new int[num];
genders = new String[num];
emails = new String[num];
salaries = new double[num];
for (int i = 0; i < num; i++) {
System.out.print("Please enter your age for person "+(i+1)+": ");
ages[i] = in.nextInt();
if (ages<20 ||ages>30){
System.out.println("invalid age please re enter again");
ages[i] = in.nextInt();
}
大家好我想在这种情况下验证用户输入它的年龄不应低于20且高于30但我得到一个错误说“运算符&gt;未定义参数类型(s)int [ ],int“我将不胜感激任何帮助
答案 0 :(得分:1)
if (ages < 20 || ages > 30){...}
应该是:
if (ages[i] < 20 || ages[i] > 30) {...}
ages
是一个int
数组。您可以对此数组的元素应用conditional operators
,但不对数组本身应用。