SWITCH
Statement
1. What is the output of the following code snippet?
public static void main(String[] args) {
int num=5;
switch(num++){
case 6:System.out.println("Num = "+6);
case 5:System.out.println("Num = "+5);
case 7:System.out.println("Num = "+7);
break;
default: System.out.println("Num = "+num);
}
}
A. Num = 6
B. Num = 5
C. Num = 5
Num = 6
D. Num = 5
Num = 7
E. Num = 5
Num = 6
Num = 7
2. What is the output of the following code snippet?
public static void main(String[] args) {
int num=6;
switch(++num){
case 6:System.out.println("Num = "+num);
break;
case 5:System.out.println("Num = "+num);
break;
case 7: System.out.println("Num = "+num);
default: System.out.println("Num = "+num);
}
}
A. Num = 5
B. Num = 7
C. Num = 6
D. Num = 6
Num = 6
E. Num = 7
Num = 7
3. What is the output of the following code snippet?
public static void main(String[] args) {
int num=9;
switch(++num){
default: System.out.println("Num = "+num);
case 4+3:System.out.println("Num = "+num);
break;
case 4+5:System.out.println("Num = "+num);
break;
case 4+4: System.out.println("Num = "+num);
break;
}
}
A. Num = 10
B. Num = 9
C. Num = 9
Num = 9
D. Num = 10
Num = 10
E. Num = 10
Num = 7
4. What is the output of the following code snippet?
public static void main(String[] args) {
for (int i = 3; i >= 0; --i) {
switch (i) {
case 1:
System.out.println(i);
break;
case 2:
System.out.println(i);
break;
case 3:
System.out.println(i);
break;
default:System.out.println(i);
}
}
}
A. 1
2
3
B. 0
1
2
3
C. 3
D. 3
2
1
E. 3
2
1
0
5. What is the output of the following code snippet?
public static void main(String[] args) {
float num = 12.5f;
switch (num++) {
case 12.5f:
System.out.println("12.5");
break;
case 13.5f:
System.out.println("13.5");
break;
case 14.5f:
System.out.println("14.5");
break;
default:
System.out.println("Default");
}
}
A. 12.5
B. 13.5
C. 14.5
D. Default
E. None of the above
6. What is the output of the following code snippet?
public static void main(String[] args) {
int num = 12;
switch (++num) {
case 12:
System.out.println("12");
case 13:
System.out.println("13");
case 14:
System.out.println("14");
return;
default:
System.out.println("Default");
}
}
A. 12
13
B. 13
14
C. 14
D. Default
E. None of the above
7. What is the output of the following code snippet?
public static void main(String[] args) {
int a = 99;
switch (a) {
case 'a':
System.out.println("a");
break;
case 'b':
System.out.println("b");
break;
case 'c':
System.out.println("c");
break;
default:
System.out.println("Default");
}
}
A. Default
B. b
C. C
D. a
E. none of the above
8. What is the output of the following code snippet?
public static void main(String[] args) {
char message[]={'t','h','e','q','u','i','c','k'};
int count1=0;
int count2=0;
for(int i=0;i<message.length;i++)
switch (message[i]) {
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':count1++;
default: count2++;
}
System.out.println(count1+ " "+count2);
}
A. 3 5
B. b. 4 4
C. 3 6
D. 3 7
E. 3 8
9. What is the output of the following code snippet?
public static void main(String[] args) {
int num=10;
switch(num++){
case 5+5: System.out.println("Expression");
break;
case 10: System.out.println("Value-10");
break;
case 11:System.out.println("Value-11");
break;
default: System.out.println("Default");
}
}
A. Expression
B. Value-10
C. c. Value-11
D. Default
E. None of the above
10. What is the output of the following code snippet?
public static void main(String[] args) {
int num=10;
switch(num++){
default: System.out.println("Default");
case 5+7: System.out.println("Expression");
break;
case 10: System.out.println("Value-10");
break;
case 11:System.out.println("Value-11");
break;
}
}
A. Default
B. Default
Expression
C. Value-10
D. Value-11
E. None of the above
No comments:
Post a Comment