如何判断一个数是否在一个数组里面 java

2025-02-26 18:32:18
推荐回答(1个)
回答1:

int [] array = {1 , 2 , 3 ,4};
boolean cunzai = false;
for (int i = 0; i < array.length; i++) {
if (array[i] == 3) { //3就是你要判断的数
cunzai = true;
}

}

if (cunzai) {
System.out.println("存在");
}else{
System.out.println("不存在");
}