Java 创建等距表
我写了这段代码,所以我知道它是有效的,但我似乎总是很难创建一个表,使我的数字均匀分布。有人能帮我使用我的最后一个方法吗?Java 创建等距表,java,Java,我写了这段代码,所以我知道它是有效的,但我似乎总是很难创建一个表,使我的数字均匀分布。有人能帮我使用我的最后一个方法吗?PlayTour(),这样当我运行程序时,我的数字表是均匀分布的,并且排列正确 public void playTour() { System.out.printf("%n%n"); //display numbers in column for (int a = 0; a < 8; a++) System.out.printf(
PlayTour()
,这样当我运行程序时,我的数字表是均匀分布的,并且排列正确
public void playTour() {
System.out.printf("%n%n");
//display numbers in column
for (int a = 0; a < 8; a++)
System.out.printf(" %d", a);
System.out.printf("%n%n");
for (int row = 0; row < chessBoard[0].length; row++) {
System.out.printf("%d ", row);
for (int column = 0; column < chessBoard[1].length; column++)
System.out.printf(" %d", chessBoard[row][column]);
System.out.println();
}
}//end method playTour
public void playTour(){
System.out.printf(“%n%n”);
//在列中显示数字
对于(int a=0;a<8;a++)
System.out.printf(“%d”,a);
System.out.printf(“%n%n”);
对于(int row=0;row<棋盘[0]。长度;row++){
System.out.printf(“%d”,第行);
for(int column=0;column
使用printf时,可以使用长度说明符
例如:
for(int a = 0; a < 8; a++)
System.out.printf("%3d ",a);
for(int a=0;a<8;a++)
System.out.printf(“%3d”,a);
将为0到8之间的每个数字使用3个位置(如3位数字),后跟一个空格。我认为这看起来更像您期望的那样:
// display numbers in column
System.out.print(" ");
for(int a = 0; a < 8; a++) {
System.out.printf("%3d", a);
}
System.out.printf("%n");
for(int row = 0; row < chessBoard[0].length; row++) {
System.out.printf("%3d ", row);
for(int column = 0; column < chessBoard[1].length; column++) {
System.out.printf("%3d", chessBoard[row][column]);
}
System.out.println();
}
请提供一个最低限度的工作实例,我们可以采取和运行。此外,预期的输出也会有所帮助。“我写了这段代码,所以我知道它是有效的。”n1:)是的..这很有帮助。谢谢
0 1 2 3 4 5 6 7
0 63 32 71 1 25 2 5 3
1 6 3 7 1 5 2 5 3
2 6 3 7 1 5 2 5 3
3 6 3 7 1 5 2 5 3
4 6 3 7 1 5 2 5 3
5 6 3 7 1 5 2 5 3
6 6 3 7 1 5 2 5 3
7 6 3 7 1 5 2 5 3