java for嵌套for循环语句_在Java中,如何在嵌套for循环中使用字母增加值?

我在学校是一名初级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(“”)之前调整代码;。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值