如何验证数组输入?

时间:2016-03-29 16:21:35

标签: java

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数组的长度。

0 个答案:

没有答案