I'm a beginner level Java student in school and I'm stuck on a challenge activity in my textbook program, I'm using a textbook from zybooks.com and in this specific activity I can only change the code that the program allows me to. Also, because of where I am at in the textbook, I can only use simple things like loops and if statements. Here are the exact directions of the activity,
Given numRows and numColumns, print a list of all seats in a theater. Rows are numbered, columns lettered, as in 1A or 3E. Print a space after each seat, including after the last. Use separate print statements to print the row and column. Ex: numRows = 2 and numColumns = 3 prints: 1A 1B 1C 2A 2B 2C.
So, what I'm currently stuck on is printing the columns incrementally as letters. Right now I'm getting 1A 2A 3A and so on when what I want is 1A 1B 1C 2A 2B 2C> How do I increment that columns row with letters?
Also, the program shouldn't run when there are no columns input but my program will print out the rows and no columns which isn't what I want either. For example, numRows = 3 and numColumns = 0, the program shouldn't print anything out but what's happening is that the program will print out only the rows like this 123. How do I get the program to not run if there is no columns input?
Here is my code
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("");
}
}
Keep in mind that I can only adjust the code that is after initializing the numRows and NumColumns variables and before the final System.out.print("");.