Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

What is the result of this code if the user enters in 0 when prompted? ArrayList option = new ArrayList < > ( ) ;

What is the result of this code if the user enters in 0 when prompted?
ArrayList option = new ArrayList<>();
option.add("deposit");
option.add("withdraw");
option.add("exit");
Scanner input = new Scanner(System.in);
System.out.print("Enter an option: ");
int selection = input.nextInt();
int index = selection -1;
if(index >=0 && index < option.size()){
System.out.println("You chose "+ option.get(index)+".");
}
else {
System.out.println("Not valid");
}
Error
You chose deposit.
Not valid
You chose 0.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions

Question

What is a verb?

Answered: 1 week ago