简体   繁体   English

声明2D Java数组字符串大小变量

[英]Declaring 2D Java array string size variables

How do I go about declaring variables in a 2D Java array that has 5 first names and 5 last names? 如何在具有5个名字和5个名字的2D Java数组中声明变量? This is what I think is correct but I am unsure: 我认为这是正确的,但是我不确定:

String[][] flNames = new String[5][5];

Also how do I go about declaring variables for a 2D array that has 5 last names and 10 assignment names that can be either essays or labs, not both. 我还要如何声明具有5个姓和10个赋值名称的2D数组的变量,这些变量既可以是论文,也可以是实验。 This is what I have : 这就是我所拥有的:

String[][] namesAssign = new String[5][10];

Yes, here's an example of adding information to the array: 是的,下面是向数组添加信息的示例:

String[][] flNames = new String[5][5];
    for (int i = 0; i < 5; i++) {
        for (int j = 0; j < 5; j++) {
            flNames[i][j] = "Test" + i + j;
        }
    }
    System.out.println(flNames[4][4]);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM