(Java)如何获得这样的输入

(Java)如何获得这样的输入,java,string,matrix,Java,String,Matrix,我需要一个代码,读取将要完成的测试数量,然后读取每个测试矩阵上的值 输入: 三, 测试1 02010 11234 1 5 6 测试2 0 22 10 11034 0 0 0 测试3 010 020 0 0 0 我的尝试: public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println("Number of tests");

我需要一个代码,读取将要完成的测试数量,然后读取每个测试矩阵上的值

输入:

三,

测试1

02010

11234

1 5 6

测试2

0 22 10

11034

0 0 0

测试3

010

020

0 0 0

我的尝试:

public static void main(String[] args) {
    Scanner input = new Scanner(System.in);
    System.out.println("Number of tests");
    int n = input.nextInt();

    String[] name = new String[n];
    int test[][] = new int[n][3];

    for (int i = 0; i < n; i++) {

        System.out.println("Name of the test" + i);

        name[i] = input.nextLine();
        System.out.println("Values");
        for (int j = 0; j < 3; j++) {
            test[i][j] = input.nextInt();
        }
    }
}
publicstaticvoidmain(字符串[]args){
扫描仪输入=新扫描仪(System.in);
系统输出打印项次(“测试次数”);
int n=input.nextInt();
字符串[]名称=新字符串[n];
整数测试[][]=新整数[n][3];
对于(int i=0;i
您需要一个三维数组而不是二维数组,因为每个测试都有一个二维数组

演示:

import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        final int ROWS = 3, COLS = 3;
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int test[][][] = new int[n][ROWS][COLS];
        for (int i = 0; i < n; i++) {
            System.out.println("Test " + (i + 1));
            for (int j = 0; j < ROWS; j++) {
                for (int k = 0; k < COLS; k++) {
                    test[i][j][k] = input.nextInt();
                }
            }
        }

        // Display
        System.out.println("Displaying...");
        for (int i = 0; i < n; i++) {
            System.out.println("Test " + (i + 1));
            for (int j = 0; j < ROWS; j++) {
                for (int k = 0; k < COLS; k++) {
                    System.out.printf("%4d", test[i][j][k]);
                }
                System.out.println();
            }
        }
    }
}
3
Test 1
0 20 10
1 12 34
1 5 6
Test 2
0 22 10
1 10 34
0 0 0
Test 3
0 10 10
0 0 20
0 0 0
Displaying...
Test 1
   0  20  10
   1  12  34
   1   5   6
Test 2
   0  22  10
   1  10  34
   0   0   0
Test 3
   0  10  10
   0   0  20
   0   0   0

是否每个测试都包含相同数量的行和列,以及要打印的示例输出是什么here@nikhil2000是的,每个测试都包含一个3x3矩阵。然后我必须从这些数据中获取一些统计数据,但首先我需要知道如何获取这些输入;-@ADGJ20-有更新吗?@ArvindKumarAvinash我如何检查有多少行只有0?非常感谢!!完成后,我无法投票,因为我不到15岁:/