【发布时间】:2013-12-19 23:41:11
【问题描述】:
我目前正在学习自学 Java 课程,对我的一项作业完全感到困惑,谁能给我一些指点?请记住,我对 Java 完全陌生,所以我需要它尽可能简单。
问题: 3. 创建一个名为 TwoDimArray 的 Java 程序并实现以下内容:
Create a two dimensional string array anArray[2][2].
Assign values to the 2d array containing any Country and associated colour.
Example:
France Blue
Ireland Green
Output the values of the 2d array using nested for loops.
我想出的代码也不起作用:
public class TwoDimArray {
public static void main(String[] args) {
char Ireland = 0;
char Green = 1;
char England = 2;
char White = 3;
char firstArray[][] = {{Ireland},{Green}};
char secondArray[][] = {{England},{White}};
System.out.println();
display(firstArray);
System.out.println();
display(secondArray);
}
public static void display(char a[][]) {
for (char row = 0; row < a .length; row++) {
for (char col = 0; col < a [row] .length; col++) {
System.out.print(a[row][col] + " ");
}
System.out.println();
}
}
}
谁能给我一些建议?我似乎在网上找不到任何对我有帮助的东西,所以我想我会来这里问。 提前致谢。
【问题讨论】:
-
“创建一个二维字符串数组”。你这样做了吗?
-
你也可以制作字符串数组。
-
我完全不知道我是怎么错过的,我会继续的。谢谢大家。
-
我想这会对你有所帮助[二维字符串数组][1] [1]:stackoverflow.com/questions/19173396/…
标签: java arrays loops multidimensional-array