package arrays;
import java.util.Iterator;
public class StringArray2D {
public static void main(String[] args) {
// TODO Auto-generated method stub
String row1[][]={{"Robert","Albert","Gilbert"},{"Fobert","Sobert","Nareg","Nari"},{"Marie","Sarie","Kharie","Aarie","Akiahsbdfuiah"}};
display2(row1);
}
public static void display2(String x[][]){
for (int row = 0; row < x.length; row++) {
for (int column = 0; column < x[row].length; column++) {
System.out.print(x[row][column] +"\t");
}
System.out.println();
}
}
public static void display(String x[][]){
for (int row = 0; row < x.length; row++) {
for (int column = 0; column < x[row].length; column++) {
System.out.println(x[row][column] + "\t");
}
System.out.println();
}
}
}
你好...我试图正确显示这个2D数组Proper Display
但我会得到像Improper Display
这样的显示方法&#34; display2&#34;工作正常,方法&#34;显示&#34;不能正常工作 我错过了什么?
答案 0 :(得分:1)
然后使用“display2”方法,有什么问题?
这是不同的:
System.out.print(x[row][column] +"\t");
VS
System.out.println(x[row][column] +"\t");
第一个写入你提供的内容,第二个写入它并添加一个新行。