Question: Algorithm Workbench choice.java The following if statement, line # 18 of choice.java , determines whether choice is equal to Y or y : if (choice
Algorithm Workbench
choice.java The following if statement, line # 18 of choice.java, determines whether choice is equal to Y or y: if (choice == 'Y' || choice == 'y')
Rewrite this statement so it makes only one comparison and does not use the || operator. (Hint: Use either the toUpperCase or toLowerCase method.)
choice.java
/** * * @author Bill Jing */ import java.util.Scanner; public class choice { public static void main(String[] args) { char choice; String choiceString = ""; Scanner in = new Scanner(System.in); System.out.println("Please enter 'Y' or 'y' for yes:"); choiceString = in.next(); choice = choiceString.charAt(0); //this is the line you need to modify if (choice == 'Y' || choice == 'y') System.out.println("Your choice is: \"Yes\""); else System.out.println("You did not chose \"Yes\""); } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
