[英]Printing 2D Array in Java
I'm trying print a 10x10 grid, I don't need any particular symbols, just the 10x10 format.我正在尝试打印 10x10 网格,我不需要任何特定符号,只需要 10x10 格式。 There's actually a lot more to the whole program but right now I'm stuck on this.
整个程序实际上还有很多内容,但现在我坚持这个。 I really just want to print *'s for a simple Pacman game.
我真的只想为一个简单的 Pacman 游戏打印 *'s。 I'm not good at programming at all, but I have to pass so I can graduate next semester.
我根本不擅长编程,但我必须通过考试才能下学期毕业。 Here is what I have so far;
这是我到目前为止所拥有的;
public class Pacman {
public static void main(String[] args) {
int columns = 0;
int rows = 0;
int[][] grid = new int[rows][columns];
for (int i = 0; i < grid.length; i++){
for (int j = 0; j < grid.length; j++){
System.out.println(grid[i][j] + " ");
}
System.out.println();
}
}
}
I don't have errors in syntax or compiling, but nothing actually prints.我没有语法或编译错误,但实际上没有打印任何内容。
public static void main(String[] args) {
int columns = 10;
int rows = 10;
int[][] grid = new int[rows][columns];
for (int i = 0; i < grid.length; i++){
for (int j = 0; j < grid.length; j++){
System.out.print(grid[i][j] + " ");
}
System.out.println();
}
}
int columns = 10;
int rows = 10;
int[][] grid = new int[rows][columns];
for (int i = 0; i < grid.length; i++)
{
for (int j = 0; j < grid.length; j++)
{
grid[i][j] = 0;
System.out.print(grid[i][j] + " ");
}
System.out.println();
}
That will print out a 10x10 with every number in the array being 0这将打印出一个 10x10,数组中的每个数字都是 0
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.