Arrays 如何比较int和array?
我是一名编程专业的学生,我需要帮助比较int和arrayArrays 如何比较int和array?,arrays,int,Arrays,Int,我是一名编程专业的学生,我需要帮助比较int和array idNumber =Integer.parseInt(JOptionPane.showInputDialog("Enter ID number:")); for (i = 0; (i < student.length) && (idNumber == student[i]); i++) { choiceIsGood = true; idNumber=Integ
idNumber =Integer.parseInt(JOptionPane.showInputDialog("Enter ID number:"));
for (i = 0; (i < student.length) && (idNumber == student[i]); i++) {
choiceIsGood = true;
idNumber=Integer.parseInt(JOptionPane.showInputDialog(“输入ID号:”);
对于(i=0;(i
我已宣布:
国际电话号码;
最终整数[]学生={2064009,2062895,2063427}
我想验证该条目是否已在我的数组中注册。
我将如何比较这一点并继续使用boolean=true;1.idNumber=Integer.parseInt(JOptionPane.showInputDialog(“输入ID号”);
1. idNumber =Integer.parseInt(JOptionPane.showInputDialog("Enter ID number:"));
2. bool choiceIsGood = false;
3. for (i = 0; (i < student.length); i++)
4. {
5. if(idNumber == student[i]) // student[i] is an int, idNumber too !
6. { // if idNumber == 2064009 or 2062895 or 2063427
7. choiceIsGood = true; // no need to continue to loop over your array
8. }
9. }
10.if(choiceIsGood)
11.{
12. // Do some stuff
13.}
2.bool choicesgood=false;
3.对于(i=0;(i
一些解释:
行:1.获取用户输入第2行。在验证系统之外声明var
第3行。检查数组中的每个项目
第5行。检查用户输入是否为数组的当前元素
第7行。将true赋值给
选项good
第10行。检查我们是否通过了
choicesgood=true
行。您从不比较两个类型不同的对象,而是比较与您的输入类型相同的数组的内容。
1.idNumber=Integer.parseInt(JOptionPane.showInputDialog(“输入ID号”);
2.bool choicesgood=false;
3.对于(i=0;(i
一些解释:
行:1.获取用户输入第2行。在验证系统之外声明var
第3行。检查数组中的每个项目
第5行。检查用户输入是否为数组的当前元素
第7行。将true赋值给
选项good
第10行。检查我们是否通过了
choicesgood=true
行。您永远不会比较两个类型不同的对象,而是比较与输入类型相同的数组的内容