由于某些原因,当我尝试在我的main方法中调用整数数组作为此方法的参数时,它无法将该参数识别为数组或其他东西,我不确定为什么会这样做。我这样称呼数组:has23([2,4])。
public static boolean has23(int[] n) {
Boolean correct = null;
while ((n.length == 2)) {
for (int i : n) {
Arrays.asList(n);
if (Arrays.asList(n).contains(2) || Arrays.asList(n).contains(3)) {
correct = true;
}
else;
correct = false;
}
}
System.out.println(correct);
return correct;
}
因为
has23([2, 4])
不是合法的Java语法。你可以做
has23(new int[] { 2, 4 })
相反。或
int[] arr = { 2, 4 };
has23(arr);
但是不是
has23({2, 4});