设二维数组为a[m][n]
boolean flag=true;
for(int i=0;i
flag=false;
break;
}
}
}
if(flag){
System.out.println("没有空值");
}else{
System.out.println("有空值");
}
写一个方法,传入一个二位数组,对二维数组进行循环遍历,若二维数组没有空值返回true,否则false。具体代码如下:
public boolean IsNull(String[][] arr) {
for (int i = 0; i < arr[0].length; i++) {
for (int j = 0; j < arr.length; j++) {
if (arr[i][j] == null) {
return false;
}
}
}
return true;
}
public class test {
public static void main(String[] args) {
String[][] s = new String[2][2];
foo(s);
}
public static void foo(String[][] arr) {
for (int i = 0; i < arr[0].length; i++) {
for (int j = 0; j < arr.length; j++) {
if (arr[i][j] == null) {
System.out.println("arr[" + i + "][" + j + "]" + "=null");
}
}
}
}
}