我试图将二维String数组复制到另一个二维String数组。然后将第二个2维String数组转换为字符串。之后打印出字符串 但字符串没有显示假设... 我试图在不使用java库的情况下这样做。
public class Train {
//public static void main (String args){
public static void main(String[] args) {
String [][] ff = { {"0","1","2","3","4","5","6","7"},
{"0","1","2","3","4","5","6","7"},
{"0","1","2","3","4","5","6","7"},
{"0","1","2","3","4","5","6","7"},
{"0","1","2","3","4","5","6","7"},
{"0","1","2","3","4","5","6","7"},
{"0","1","2","3","4","5","6","7"},
{"0","1","2","3","4","5","6","7"} };
String[][] IP = new String[8][8];
int x=0, y=0;
for(int i = 1; i < 8; i +=2){
for(int j = 7; j>=0 ; j--){
y= 0;
IP[x][y]=ff[j][i];
System.out.print(IP[x][y]);
y++;
}
if (i==7){
i=-2;
x++;
}
}
String zz= "";
for( int p = 0; p<8;p++){
for( int q= 0 ; q< 8; q++){
zz += IP[p][q];
System.out.print(zz);
}
}
}
}
谢谢
答案 0 :(得分:0)
使用此:String yourString = Arrays.toString(yourArray);
答案 1 :(得分:0)
System.out.print(IP);
在Java中,每个对象都有toString()
方法,默认显示类名表示,然后添加@
,然后添加哈希码。
您应该使用Arrays#deepToString
:
System.out.println(Arrays.deepToString(yourArray));
答案 2 :(得分:0)
该行
System.out.print(IP);
只是打印出Object表示。当您创建zz
字符串时,您几乎就在那里。尝试在迭代后打印出来。
由于您不想使用任何Java库,因此需要再次遍历该数组。当然,如果您假设java.util.*
是一个库。
答案 3 :(得分:0)
如果您不想使用该库:
String ffStr = "";
for (String[] sArray : ff) {
for (String s : sArray) {
ffStr += s;
}
}
System.out.println(ffStr);