Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

WHAT IS THE USED OF INT I AND J IN THIS CODE AND WHAT IS AN ALTERNATIVE NAME FOR IT GIVE ATLEAST 3 import java.util.Scanner;

WHAT IS THE USED OF INT I AND J IN THIS CODE AND WHAT IS AN ALTERNATIVE NAME FOR IT GIVE ATLEAST 3

import java.util.Scanner; /* * This is BusSeatsApp class * */ public class BusSeatsApp { public static void main(String[] args) { /* * sc is a Scanner class object.We can read the * data from keyboard. * */ Scanner sc = new Scanner(System.in); /* * Creating two dimensional String array and * initializing with "*" * */ String[][] bus = new String[10][4]; for(int row=0;row<10;row++){ for(int col=0;col<4;col++){ bus[row][col] = "*"; } } /* * choice is an integer variable. * It will hold user choice.Whether he wants to continue or exit. * Initially we are giving positive value,later we are getting from user. * */ int choice = 999; while(choice>=0){ /* * The below two nested for loops will print column and row headers. * and contents of the bus array. * */ for(int row=0;row<11;row++){ for(int col=0;col<5;col++){ if(row==0){ if(col==0){ System.out.print("\t"); }else{ System.out.print("col "+(col)+"\t"); } } if(col==0){ if(row==0){ System.out.print(""); }else{ System.out.print("row "+(row)+"\t"); } } /* * The below code print bus array content. * */ if(row!=0&&col!=0){ if(col==1){ System.out.print("|"+bus[row-1][col-1]+"\t"); }else{ System.out.print(bus[row-1][col-1]+"\t"); } } } System.out.println(""); } /* * We are asking the user which seat he wants to reserve. * After getting row and col values we are assigning "X" * */ System.out.println("Enter row and column number to reserve separated by space (Enter a negative number to exit):"); choice = sc.nextInt(); /* * we are checking choice is negative or positive. * If it is negative then we terminating the program. * */ if(choice>=0){ int i = choice; int j = sc.nextInt(); bus[i-1][j-1]="X"; } } }

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intranet And Web Databases For Dummies

Authors: Paul Litwin

1st Edition

0764502212, 9780764502217

More Books

Students also viewed these Databases questions

Question

What are the workforce planning challenges at BCC?

Answered: 1 week ago