Question
why int choice is 999 in this java code original code import java.util.Scanner; public class BusSeatsApp { public static void main(String[] args) { Scanner sc
why int choice is 999 in this java code
original code
import java.util.Scanner; public class BusSeatsApp { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String[][] bus = new String[10][4]; for(int row=0;row<10;row++){ for(int col=0;col<4;col++){ bus[row][col] = "*"; } }
int choice = 999; while(choice>=0){ for(int row=0;row<11;row++){ for(int col=0;col<5;col++){ //these conditions below are repeatedly testing but they are satisifed only once for iteration variable //so it increases complexity //check modified code below 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"); } }
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(""); } System.out.println("Enter row and column number to reserve separated by space (Enter a negative number to exit):"); choice = sc.nextInt(); 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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started