int x = 100;
int a = x++;
int b = ++x;
int c = x++;
int d = a<b?(a<c)?a:(b<c)?b:c;
System.out.println(d);
a) 100 b) 101 c) 102 d) Compile error
Wrong! Try again.
Wrong Again! Try one more chance.
Wrong! The correct answer is d) Compile error : The ternary expression is not complete. It's like, if(a<b) {if(a<c) a; else if(b<c) b; else c; } else ...
Correct! Compile error : The ternary expression is not complete. It's like, if(a<b) {if(a<c) a; else if(b<c) b; else c; } else ...
2. What is the output?
int n = 10;
do {
System.out.print(n-- + " ");
} while (n-- >0);
a) 10 8 6 4 2 b) 10 8 6 4 2 0 c) 9 7 5 3 1 -1 d) 9 7 5 3 1
Wrong! Try again.
Wrong Again! Try one more chance.
Wrong! The correct answer is b) 10 8 6 4 2 0
Correct! 10 8 6 4 2 0
3. To get output : true Done
1. boolean option=true;
2. switch (option) {
3. case true:
4. System.out.println("true");
5. break;
6. default:
7. System.out.println("default");
8. break;
9. }
10. System.out.println("Done");
A. line 1: String option="true";
B. line 1: int option= 1;
C. line 3: case "true":
D. line 3: case 1:
E. line 3: case false
a) A with C or B with D b) A with C only c) B with D only d) No change needed
Wrong! Try again.
Wrong Again! Try one more chance.
Wrong! The correct answer is a) A with C or B with D switch accepts byte, char, String, enum or int values only
Correct! A with C or B with D switch accepts byte, char, String, enum or int values only
4. What changes can get output 43210?
public static void main(String... args) {
int n = 5;
while (isAvailable(n)) {
System.out.print(n);
}
}
public static boolean isAvailable(int n) {
return n-->0?true:false;
}
a) Change isAvailable(n) to isAvailable(n--) b) Change System.out.print(n) to System.out.print(--n) c) Any of the above d) None of the above