In Java; 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 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();numColumns = currentColumnLetterfor(currentRow = 0; currentRow < numRows;currentRow++){for(currentColumn = =System.out.println("");}}

Respuesta :

Answer:

The solution code is written in Java.

  1. import java.util.Scanner;
  2. public class Main {
  3.    public static void main(String[] args) {
  4.        String letters[] = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J"};
  5.        Scanner scnr = new Scanner(System.in);
  6.        int numRows;
  7.        int numColumns;
  8.        int currentRow;
  9.        int currentColumn;
  10.        numRows = scnr.nextInt();
  11.        numColumns = scnr.nextInt();
  12.        for(currentRow = 0; currentRow < numRows;currentRow++){
  13.            for(currentColumn =0; currentColumn < numColumns; currentColumn++)
  14.            {
  15.                System.out.print((currentRow + 1) + letters[currentColumn] + " ");
  16.            }
  17.        }
  18.    }
  19. }

Explanation:

Firstly, we need to create an array to hold a list of letters (Line 6). In this solution, only letters A - J are given for simplicity.

Next, we declare all the variables that we need, numRows, numColumns, currentRow and currentColumn (Line 8 - 11).

Next, we use Scanner object, scnr to prompt user to input integer for numRows and numColumns (Line 12-13).

At last, we use two-layer for loops to traverse through the number of rows and columns and print out the currentRow and currentColumn (Line 15-19). Please note the currentRow is added by 1 as the currentRow started with 0. To print the letter, we use currentColumn as an index to take out the letter from the array.