WorksheetsArithmetic Types Declare Initialize Relation Logical Ops
Total questions: 16
Worksheet time: 1hrs 20mins
Which Java type(s) can hold decimals? (Choose all that apply)
int
float
double
String
34 % 35 % 36 % 37 % 38
0.00001919212
38
34
Impossible
What does the following code print?
System.out.println(1 / 3);
0.3333333333333333
0
an error
0.3
What will the following code print?
system.out.println(2.0 / 9);
0.222222222222222 (14 - 15 significant digits)
0
error
Consider the following code segment.
System.out.print("Java is");
System.out.println("fun ");
System.out.print("and cool!");
What is printed as a result of executing the code segment?
Java is fun and cool!
Java isfun
and cool!
Java is
fun
and cool!
Java is fun
and cool!
Which of the following correctly assigns a value to the variable x?
x int = 5;
int x;
x = 5;
int x
x = 5
Which of the following correctly declares a variable x of type int?
x int = 5;
int x;
x = 5;
int x
x = 5
Consider the following code segment.
// Geez, textbooks are expensive!
double bookPrice = 79.4; // Line 1
int numBooks = 5; // Line 2
System.out.println(bookPrice); // Line 3
System.out.println(numBooks); // Line 4
// Prices dropped, so I bought more!
bookPrice = 56; // Line 5
numBooks = 8.5; // Line 6
System.out.println(bookprice); // Line 7
System.out.println(numBooks); // Line 8
Does this code contain any syntax errors? If so, on which line(s)?
Select ALL that apply!
Line 5 contains an error.
Line 6 contains an error.
Line 7 contains an error.
Line 8 contains an error.
This contains no errors.
Consider the following code
int x, y, z;
x = 3;
y = 7;
z = 21;
x = y;
y = z;
System.out.print(x);
System.out.print(" ");
System.out.print(y);
Which of the following will be displayed after the code is run?
3 7
21 21
3 3
7 21
What value of body_temp would yield "You have hypothermia."?
97
96
101
100.4
Given the following code segment, which of the following is this equivalent to?
What error message will be displayed when this code fragment is executed?
int x;
System.out.println(x);
Incompatible type error
Arithmetic error
x may not have been initialized
syntax error
Evaluate 4 == 4 || 193775/56 >3460
true
false
error
3,460.267857142857
Which expression is logically equivalent to !(x > y || y <= z) ?
x < y || y >=z
x < y && y >= z
x <= y || y > z
x <= y && y > z
What error message will be displayed when this code fragment is executed?
int x = 3.14;
System.out.println(x);
incompatible types error
Arithmetic error
x may not have been initialized
syntax error
Evaluate 4==5 && 193775/56 >3460
true
false
error
3,460.267857142857
