Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

The Structure Of The Relational Database Model

Authors: Jan Paredaens ,Paul De Bra ,Marc Gyssens ,Dirk Van Gucht

1st Edition

3642699588, 978-3642699580

More Books

Students also viewed these Databases questions