gpt4 book ai didi

java - 如何使用字符打印锯齿状数组?

转载 作者:太空宇宙 更新时间:2023-11-04 12:38:42 24 4
gpt4 key购买 nike

public static void main(String [] args) {
char[][]tictactoe= {{'#','#'},{'#','#','#','#','#'},{'#','#','#','#'}};
System.out.println(tictactoe);
}

我们希望它使用二维数组打印 # 符号我做错了什么

最佳答案

你必须使用循环:

char[][]tictactoe= {{'#','#'},{'#','#','#','#','#'},{'#','#','#','#'}};

StringJoiner sj = new StringJoiner(", ", "[", "]");
for(char[] arr : tictactoe)
sj.add(Arrays.toString(arr));
System.out.println(sj.toString());

输出:

[[#, #], [#, #, #, #, #], [#, #, #, #]]

关于java - 如何使用字符打印锯齿状数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37051632/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com