Question

(Java Zybooks) 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 s...

(Java Zybooks)

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();

/* Your solution goes here */

System.out.println("");
}
}

1 0
Add a comment Improve this question Transcribed image text
✔ Recommended Answer
Answer #1

Program:

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;
       //read number of rows
       System.out.print("Enter number of rows: ");
       numRows = scnr.nextInt();
       //read number of columns
       System.out.print("Enter number of columns: ");
       numColumns = scnr.nextInt();

       /* Your solution goes here */
       System.out.println("");
       //loop that iterates through each row
       for (currentRow = 1; currentRow <= numRows; currentRow++)
       {
           //set the column letter to A
           currentColumnLetter = 'A';
           //loop that iterates through each column
           for (currentColumn = 1; currentColumn <= numColumns; currentColumn++)
           {
               //print the row number
               System.out.print("" + currentRow);
               //print the column letter followed by space
               System.out.print(currentColumnLetter + " ");
               //increment currentColumnLetter
               currentColumnLetter++;
           }
       }
   }
}

Output:

console X <terminated> NestedLoops [Java Application] CProgram Fi Enter number of rows: 2 Enter number of columns: 3 1A 1B 1CConsole 3 <terminated> Nestedloops Java Application] C: Program F Enter number of rows: 2 Enter number of columns: 5 1A 1B 1C

Program Screenshot:

NestedLoops.java 3 1 import java.util.Scanner; 2 3 public class NestedLoops { 4 public static void main (String [] args) Scan

Add a comment
Know the answer?
Add Answer to:
(Java Zybooks) 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 s...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Similar Homework Help Questions
  • (Java Zybooks) Given numRows and numColumns, print a list of all seats in a theater. Rows...

    (Java Zybooks) 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...

  • In Java; Given numRows and numColumns, print a list of all seats in a theater. Rows...

    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...

  • Given numRows and numColumns, print a list of all seats in a theater. Rows are numbered,...

    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. Ex: numRows = 2 and numColumns = 3 prints: 1A 1B 1C 2A 2B 2C c++. #include <iostream> using namespace std; int main() { int numRows; int numColumns; int currentRow; int currentColumn; char currentColumnLetter; cin >> numRows; cin >> numColumns; cout << endl; return 0; }

  • C++ Given numRows and numColumns, print a list of all seats in a theater. Rows are...

    C++ 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. Ex: numRows = 2 and numColumns = 3 prints: 1A 1B 1C 2A 2B 2C #include <iostream> using namespace std; int main() { int numRows; int numColumns; int currentRow; int currentColumn; char currentColumnLetter; cin >> numRows; cin >> numColumns; /* Your solution goes here */ cout...

  • C code Given numRows and numColumns, print a list of all seats in a theater. Rows...

    C code 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. Ex: numRows = 2 and numColumns = 3 prints: 1A 1B 1C 2A 2B 2C #include <stdio.h> int main(void) { int numRows; int numColumns; int currentRow; int currentColumn; char currentColumnLetter; scanf("%d", &numRows); scanf("%d", &numColumns); /* Your solution goes here */ printf("\n"); return 0; }

  • Print numbers 0, 1, 2, ..., userNum as shown, with each number indented by that number...

    Print numbers 0, 1, 2, ..., userNum as shown, with each number indented by that number of spaces. For each printed line, print the leading spaces, then the number, and then a newline. Hint: Use i and j as loop variables (initialize i and j explicitly). Note: Avoid any other spaces like spaces after the printed number. Ex: userNum = 3 prints: 0 1 2 3 Sample program: #include <stdio.h> int main(void) { int userNum = 0; int i =...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT