WorksheetsJava test 02
Total questions: 30
Worksheet time: 1hrs 18mins
Is "X" printed?
YES
NO
Is "X" printed?
YES
NO
Click ALL answers which result in an "X" printed.
a = 3, b = 3, c = 3
a = 5, b = 4, c = 7
a = 1, b = 3, c = 5
a = 6, b = 4, c = 3
a = 5, b = 5, c = 3
What is output?
0
1
2
3
What is output?
-1
0
1
2
What is output?
-1
0
1
2
Given : a = 1, b = 2
if ( missing ) print "X"
Select ALL expressions which can be used for missing to result in an "X" being printed.
a < 2
a != b
a > b
b >= a
b == a
Which expression is the same as (a != b) ?
! (a == b)
! (a >= b)
! (a < b)
! (b >= a)
Which expression is the same as (a == b) ?
! (a != b)
! (a >= b)
! (a < b)
! (b >= a)
Given : a = 1, b = 2
if ( missing ) print "X"
Select ALL expressions which can be used for missing to result in an "X" being printed.
a < 2 && b == 2
a != b || a == b
a > b
! (b >= a)
b == a
Which is the alternative to SWITCH in Java language?
break, continue
for, while
if-else
goto, exit
A SWITCH statement accepts ___ type of data as input.
byte
short
int
String (case sensitive)
All of above
What is the output of Java program with SWITCH below?
int a=10;
switch(a)
{
case 2: System.out.println("TWO");
break;
case 10: System.out.println("TEN");
break;
}
No Output
TEN
Compiler error as there is no break
None
Which way is a correct way to write an if statement in Java?
if (1 > 0)
{
System.out.println("1 is greater than 0");
}
if (1 > 0) ;
{
System.out.println("1 is greater than 0");
}
if (1 > 0)
[
System.out.println("1 is greater than 0");
]
If (1 > 0)
{
System.out.println("1 is greater than 0");
};
What is output by the code? Pretend it says System.out.println
2
3
4
5
6
What is output by the code?
123
12
1234
12345
4321
1 2 4 8 16 32 64
1 2 4 8 16 32
2 4 8 16 32 64
2 4 8 16 32
4 8 16 32 64
200 66 22 7 2
66 22 7 2
200 66 22 2
200 66 22
7
How many stars are printed?
7
3
4
5
Infinite Loop
How many times does the loop print a *
40
20
24
30
Infinite Loop
What does the following code print?
5 6 7 8 9
4 5 6 7 8 9 10 11 12
3 5 7 9 11
3 4 5 6 7 8 9 10 11 12
How many times does the following method print a *?
9
6
7
10
1 2 4 8 16 32 64
1 2 4 8 16 32
2 4 8 16 32 64
2 4 8 16 32
4 8 16 32 64
10
15
17
22
25
2
5
7
9
13
20
What is output by the code? Pretend it says System.out.println
2
3
4
5
6
What is ouptut by the code? Pretend it says System.out.println
2
3
4
5
6
What is output by the code?
123
12
1234
12345
4321
Pretend it says System.out.println
1383
83
1813
181383
1318
