所以我在这里遇到我的代码的问题。我基本上想做的就是为每个BC [0]分配一个值,并为BC01 [0]加1,向BC02 [0]加2,为每条船都这样做。(试图制造战舰(高级))
但是我所能打印的是
[[I@7852e922
反正这是我的代码
public class dogs {
public static int BC00 [] = {0,0};
public static int BC01 [] = {BC00[0],BC00[1]};
public static int BC02 [] = {BC00[0],BC00[1]};
public static int boat0[][] = {BC00, BC01, BC02}; //location cells boat[0][0]
public static int BC10 [] = {BC01[0], BC01[1]};
public static int BC11 [] = {BC01[0], BC01[1]};
public static int BC12 [] = {BC01[0], BC01[1]};
public static int boat1 [][] = {BC10, BC11, BC12};
public static int BC20 [] = {BC02[0], BC02[1]};
public static int BC21 [] = {BC02[0], BC02[1]};
public static int BC22 [] = {BC02[0], BC02[1]};
public static int boat2 [][] = {BC20, BC21, BC22};
public int NH; // Number of hits
public static int allBoats [][][] = {boat0, boat1, boat2};
public static int rand;
public static int n = 0;
public static void main(String[] args) {
for (int x = 0; x <= 2; x++) {
Random gen = new Random();
rand = gen.nextInt(6) + 1;
allBoats[x][0][0] = (int) rand;
while(n <= 2) { //give boatCells locations
allBoats[n][1][1] = allBoats[n][1][1] + 1;
allBoats[n][2][1] = allBoats[n][2][1] + 2;
n++;
} // end of while loop
} // end of For loop
System.out.println(boat0);
} // end of public static void main(String[] args)
} // end of dogs class
使用
System.out.println(Arrays.deepToString(boat0));
代替
System.out.println(boat0);
正如@ChristianKuetbach所建议的那样,必须理解,在Java中,toString()
-Mothod通常并不表示“生成用户可读的字符串的方法” ,这一点很重要。大多数类都会打印ClassName @ HashCode。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句