Font size
WorksheetsJava Math
Total questions: 15
Worksheet time: 12mins
What will the following code segment print?
System.out.println(4 / 5);
(a)
What will the following code segment print?
System.out.println(4 * 2.0);
(a)
What will the following code segment print?
System.out.println("b" + 2 * 2);
(a)
What will the following code segment print?
System.out.println(1 / 2.0);
(a)
What will be the value in variable x after this code segment is executed?
int x = 5.0 + 2;
7
7.0
There will be a runtime error
There will be a syntax error
5.02
What will be the value in variable x after this code segment is executed?
String x = "" + 4 + 2;
"6"
"6.0"
There will be a runtime error
There will be a syntax error
"42"
What will the following code segment print?
System.out.println(17 % 3);
(a)
What will the following code segment print?
System.out.println(6 % 9);
(a)
What will be the value in variable x after this code segment is executed?
double x = 5.0 + 2;
7
7.0
There will be a runtime error
There will be a syntax error
5.02
What will be the value in variable x after this code segment is executed?
int x = (int) 5.0 / 2;
2
2.5
There will be a runtime error
There will be a syntax error
3
What will be the value in variable x after this code segment is executed?
double x = (double) 5 / (int) 2
2
2.5
There will be a runtime error
There will be a syntax error
2.0
What will be the value in variable x after this code segment is executed?
double x = (int) (1.0 / 2)
0.5
0.0
There will be a runtime error
There will be a syntax error
0
What will the following statement print?
System.out.println(Math.sqrt(9));
(a)
What will be the range of possible values generated by the following statement for x?
double x = Math.random() * 8 - 5;
[0,3)
[−5,3)
[−5,8)
[0,8)
[3,8)
What will the following statement print?
System.out.println(Math.pow(2,3));
(a)
