package javaapplication90;
import java.util.Scanner;
public class JavaApplication90 {
public static int row;
public static int col;
public static int matries[][];
public static int i, j;
public static void main(String[] args) {
araies();
}
public static void araies() {
Scanner c = new Scanner(System.in);
System.out.println("insert the numbers of row");
row = c.nextInt();
System.out.println("insert the numbers of col");
col = c.nextInt();
matries = new int[row][col];
for (i = 0; i < row; i++) {
for (j = 0; j < col; j++) {
matries[i][j] = c.nextInt();
}
break;
}
System.out.println("the result of array");
for (int i = 0; i < row; i++) {
for (int j = 0; j < col; j++) {
System.out.println(matries[i][j]);
}
break;
}
}
}
我想创建一个条件,这样如果行数或列数不等于数组数组的长度,那么就打破。例如,如果row
为3且col
为3,并且用户输入
123456
458
458
然后我想抛出异常,因为col数组的长度不等于col数组的长度。