将输入存储在3维数组中

时间:2015-09-09 07:42:47

标签: java arrays input

我想存储想要使用我的java程序测试的不同测试用例的输入。 在示例输入下面:

Get-AzureSqlDatabase

下面:

  • 第1行 - 没有测试用例。
  • 阵列M和N的第二行长度。
  • M阵列的第3行元素。
  • 第4行:N数组的元素。

我的问题是,如何在运行时存储所有这些元素,并将它们作为输入提供给我的java类。

1 个答案:

答案 0 :(得分:0)

/*
     * Sharing the code here with . Yes,there will be multiple test cases in
     * the input Suggest any better way if you find
     */
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    int testcases = Integer.parseInt(br.readLine());
    String readinput = "";
    int count = 0;
    int[][][] array = new int[testcases][3][];
    for (int i = 0; i <= array.length; i++) {
        readinput = "";
        count = 0;
        for (int j = 0; j < array[i].length; j++) {
            readinput = br.readLine();
            count = readinput.split(" ").length;
            String[] data = new String[count];
            data = readinput.split(" ");
            System.out.println(Arrays.toString(data));
            for (int k = 0; k < count; k++) {

                array[i][j][k] = Integer.parseInt(data[k]);
            }

        }

    }
相关问题