我在学校是一名初级Java学生,在我的教科书程序中,我一直在进行挑战活动,我正在使用zybooks.com上的一本教科书,在这个特定的活动中,我只能更改程序允许我更改的代码。另外,由于我在课本上的位置,我只能使用循环和if语句等简单的东西。下面是活动的确切方向,
给定人数和人数,打印剧院所有座位的列表。如1A或3E所示,行是编号的,列是字母。在每个座位后(包括最后一个座位后)打印一个空格。使用单独的打印语句打印行和列。示例:numRows=2,numColumns=3打印:1a1b1c2a 2b2c。
所以,我现在要做的是以字母递增方式打印列。现在我得到的是1a2a3a等等,而我想要的是1a1b1c2a 2b2c2c>如何用字母递增列行?
这是我的密码
import java.util.Scanner;
public class NestedLoops {
public static void main (String [] args) {
Scanner scnr = new Scanner(System.in);
int numRows;
int numColumns;
int currentRow;
int currentColumn;
char currentColumnLetter;
numRows = scnr.nextInt();
numColumns = scnr.nextInt();
//what the text book allows me edit
for(currentRow = 1; currentRow <= numRows; ++currentRow){
System.out.print(currentRow);
currentColumnLetter = 'A';
for(currentColumn = 1; currentColumn <= numColumns; ++currentColumn){
currentColumn = currentColumnLetter;
System.out.print(currentColumnLetter + " ");
}
++currentColumnLetter;
}//the textbook won't let me edit the lines after this brace
System.out.println("");
}
}
请记住,我只能在初始化numRows和NumColumns变量之后以及在最终的System.out.print(“”)之前调整代码;。