Given the code fragment:
Which modification enables the code fragment to print TrueDone?
A. Replace line 5 With String result = "true"; Replace line 7 with case "true":
B. Replace line 5 with boolean opt = l; Replace line 7 with case 1=
C. At line 9, remove the break statement.
D. Remove the default section.
A
public static void main(String[] args) {
// boolean opt= true;
//A
String result=”true”;
switch (result){
case “true”:
System.out.println(“True”);
break;
default:
System.out.println(“******”);
}
System.out.println(“Done”);
}
Answer A:
Switch statement does not support boolean expressions or variables.
A