If x is currently equal to 5, what will the value of x be after the switch state
ID: 3573263 • Letter: I
Question
If x is currently equal to 5, what will the value of x be after the switch statement executes? 5 10 6 8 If x is currently equal to 3, what will the value of x be after the switch statement executes? 5 10 12 11 6 Rewrite the following if-else statement as an equivalent switch statement. if (letter = = 'A') System.out.println("Excellent"); else if (letter = = 'B') System.out.println("You can do better"); else if (letter = = 'C) System.out.println("Try harder"); else if (letter = = 'D') System.out.println("Try much harder"); else System.out.println("Try another major!");Explanation / Answer
switch(letter){
case 'A' : {System.out.println("Excellent"); break;}
case 'B' : {System.out.println("You can do better"); break;}
case 'C' : {System.out.println("Try harder"); break;}
case 'D' : {System.out.println("Try much harder"); break;}
//this will execute if all fails
default: System.out.println("Try another major!");
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.