Consider the following code segment:
Line 1: int a = 10;
Line 2: double b = 10.7;
Line 3: double c = a + b;
Line 4: int d = a + c;
Line 5: System.out.println(c + " " + d);
What will be output as a result of executing the code segment?
Java Basics #2
Quiz
•
Computers
•
10th - 12th Grade
•
Hard
Jennifer Hoagland
Used 63+ times
FREE Resource
7 questions
Show all answers
1.
MULTIPLE CHOICE QUESTION
15 mins • 1 pt
Consider the following code segment:
Line 1: int a = 10;
Line 2: double b = 10.7;
Line 3: double c = a + b;
Line 4: int d = a + c;
Line 5: System.out.println(c + " " + d);
What will be output as a result of executing the code segment?
20 20
20.0 30
20.7 31
20.7 30.7
Nothing will be printed because of a compile-time error.
2.
MULTIPLE CHOICE QUESTION
15 mins • 1 pt
Consider the following code segment:
Line 1: int a = 10;
Line 2: double b = 10.7;
Line 3: int d = a + b;
Line 3 will not compile in the code segment above. With which of the following statements could we replace this line so that is compiles?
I. int d = (int) a + b;
II. int d = (int) (a + b);
III. int d = a + (int) b;
I
II
III
I and III
II and III
3.
MULTIPLE CHOICE QUESTION
15 mins • 1 pt
Consider the following code segment:
Line 1: int a = 11;
Line 2: int b = 4;
Line 3: double x = 11;
Line 4: double y = 4;
Line 5: System.out.print(a / b);
Line 6: System.out.print(", ");
Line 7: System.out.print(x / y);
Line 8: System.out.print(", ");
Line 9: System.out.print(a / y);
What is printed as a result of executing the code segment?
3, 2.75, 3
3, 2.75, 2.75
2, 3, 2
2, 2,75, 2.75
Nothing will be printed because of a compile-time error.
4.
MULTIPLE CHOICE QUESTION
15 mins • 1 pt
Consider the following code segment:
int var = 12;
var = var % 7;
var = var - 1;
System.out.println(var);
What is printed as a result of executing the code segment?
0
1
2
4
5
5.
MULTIPLE CHOICE QUESTION
15 mins • 1 pt
Consider the following code segment:
int count = 5;
double multiplier = 2.5;
int answer = (int)(count * multiplier);
answer = (answer * count) % 10;
System.out.println(answer);
What is printed as a result of executing the code segment?
0
2.5
6
12.5
60
6.
MULTIPLE CHOICE QUESTION
15 mins • 1 pt
Assume that a, b, and c have been declared and initialized with int values. The expression
!(a > b || b <= c)
is equivalent to which of the following?
a > b && b <= c
a <= b || b > c
a <= b && b > c
a < b || b >= c
a < b && b >= c
7.
MULTIPLE CHOICE QUESTION
15 mins • 1 pt
Assume that x, y, and z have been declared as follows:
boolean x = true;
boolean y = false;
boolean z = true;
Which of the following expressions evaluates to true?
x && y && z
x && y || z && y
!(x && y) || z
!(x || y) && z
x && y || !z
10 questions
AppsLab_Q2
Quiz
•
10th Grade - Professi...
10 questions
Программирование C#
Quiz
•
1st - 10th Grade
10 questions
C#
Quiz
•
11th Grade
12 questions
C++ References
Quiz
•
6th - 12th Grade
12 questions
Java Strings
Quiz
•
9th - 12th Grade
10 questions
Session 1
Quiz
•
9th - 12th Grade
10 questions
Variables in C++
Quiz
•
9th - 12th Grade
10 questions
JS Practice: ITS Certification
Quiz
•
12th Grade
15 questions
Character Analysis
Quiz
•
4th Grade
17 questions
Chapter 12 - Doing the Right Thing
Quiz
•
9th - 12th Grade
10 questions
American Flag
Quiz
•
1st - 2nd Grade
20 questions
Reading Comprehension
Quiz
•
5th Grade
30 questions
Linear Inequalities
Quiz
•
9th - 12th Grade
20 questions
Types of Credit
Quiz
•
9th - 12th Grade
18 questions
Full S.T.E.A.M. Ahead Summer Academy Pre-Test 24-25
Quiz
•
5th Grade
14 questions
Misplaced and Dangling Modifiers
Quiz
•
6th - 8th Grade
17 questions
Chapter 12 - Doing the Right Thing
Quiz
•
9th - 12th Grade
30 questions
Linear Inequalities
Quiz
•
9th - 12th Grade
20 questions
Types of Credit
Quiz
•
9th - 12th Grade
20 questions
Taxes
Quiz
•
9th - 12th Grade
17 questions
Parts of Speech
Quiz
•
7th - 12th Grade
20 questions
Chapter 3 - Making a Good Impression
Quiz
•
9th - 12th Grade
20 questions
Inequalities Graphing
Quiz
•
9th - 12th Grade
10 questions
Identifying equations
Quiz
•
KG - University