Coding 4 All 2023 Java Final
Quiz
•
Computers
•
University
•
Practice Problem
•
Medium
Coding All
Used 65+ times
FREE Resource
Enhance your content in a minute
33 questions
Show all answers
1.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
In order to compare int, float and double variables, you can use <, >, ==, !=, <=, >=, but to compare char and String variables, you must use compareTo(), equals()and equalsIgnoreCase().
True
False
Answer explanation
In order to compare int, float and double variables, you can use <, >, ==, !=, <=, >=, but to compare char and String variables, you must use compareTo(), equals()and equalsIgnoreCase().
2.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Assume that boolean done = false, int x = 10, int y = 11, String s = "Help" and String t = "Goodbye". Then the expression (!done && x <= y) is true.
True
False
Answer explanation
Since done is false, !done is true. Since 10 < 11, x <= y is true. Therefore, the entire expression is true.
3.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Assume that boolean done = false, int x = 10, int y = 11, String s = "Help" and String t = "Goodbye". Then the expression (s.concat(t).length() < y) is true.
True
False
Answer explanation
Concatenating s and t gives a String that is 11 characters long and 11 < 11 is false.
4.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
f you create an ArrayList without specifying the type of element, the ArrayList will store Object references which means you can put any type of object in the list.
True
False
5.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Which of the sets of statements below will add 1 to x if x is positive and subtract 1 from x if x is negative but leave x alone if x is 0?
if (x > 0) x++;
else x--;
if (x > 0) x++;
else if (x < 0) x--;
if (x > 0) x++;
if (x < 0) x--;
if (x == 0) x = 0;
else x++;
x--;
Answer explanation
In B, if x is positive, x++ is performed, else if x is negative x-- is performed and otherwise, nothing happens, or x is unaffected. In A, C, D and E, the logic is incorrect. In A, x-- is done if x is not positive, thus if x is 0, x becomes -1 which is the wrong answer. In C, if x is positive, then x++ is performed. In either case, the next statement is executed and if x is not negative, the else clause is performed setting x to 0. So if x is positive, it becomes 0 after this set of code. In D, x++ and x-- are both performed if x is not 0. And in E, this code does not attempt to determine if x is positive or negative, it just adds one and then subtracts one from x, leaving x where it started.
6.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Consider the following code that will assign a letter grade of 'A', 'B', 'C', 'D', or 'F' depending on a student's test score.
if (score >= 90) grade = 'A';
if (score >= 80) grade = 'B';
if (score >= 70) grade = 'C';
if (score >= 60) grade = 'D';
else grade = 'F';
This code will work correctly in all cases.
This code will work correctly only if the grade is greater than or equal to 60.
This code will work correctly only if the grade is less than 60.
This code will work correctly only if the grade is less than 70.
This code will not work correctly under any circumstances.
Answer explanation
The problem with this code is that it consists of three if statements followed by one if-else statement, rather than a nested if-else statement. So the logic is improper. If the student's grade falls into the 'A' category, then all 4 conditions are true and the student winds up with a 'D'. If the student's grade falls into the 'B' category, then the first condition is false, but the next three are true and the student winds up with a 'D'. If the student's grade falls into the 'D' category, then the only condition that is true is the one that tests for 'D' and so the grade is assigned correctly. If the student's grade falls into the 'F' category, then none of the conditions are true and an 'F' is assigned correctly. So, only if the grade is less than 70 does the code work correctly.
7.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What is wrong, logically, with the following code?
if (x > 10)
System.out.println("Large");
else if (x > 6 && x <= 10)
System.out.println("Medium");
else if (x > 3 && x <= 6)
System.out.println("Small");
else
System.out.println("Very small");
There is no logical error, but there is no need to have x <= 10 in the second conditional or x <= 6 in the third conditional.
There is no logical error, but there is no need to have x > 6 in the second conditional or x > 3 in the third conditional.
The logical error is that no matter what value x is, Very small is always printed out.
The logical error is that no matter what value x is, Large is always printed out.
There is nothing wrong with the logic at all.
Answer explanation
Because this is a nested if-else statement, if (x>10)is true, then the first println statement is executed and the rest of the statement is skipped. If (x>10)is not true, then the first else clause is executed and the next if condition is tested. At this point, (x>10)is known to be false and therefore (x<=10)must be true, so there is no need to check this inequality. Similarly, if (x>6)is false, then the second else clause is executed and the third if condition is tested. However, (x<=6)must be true, so there is no need to check this inequality.
Create a free account and access millions of resources
Create resources
Host any resource
Get auto-graded reports

Continue with Google

Continue with Email

Continue with Classlink

Continue with Clever
or continue with

Microsoft
%20(1).png)
Apple
Others
By signing up, you agree to our Terms of Service & Privacy Policy
Already have an account?
Similar Resources on Wayground
32 questions
World Wide Web Brainstorming!
Quiz
•
University
30 questions
โปรแกรมนำเสนอ
Quiz
•
University
29 questions
SQL Basics
Quiz
•
University
30 questions
Round_1 (B)| Coding Combat 2.0
Quiz
•
University
35 questions
Repaso Arquitectura & Organización de Computadoras
Quiz
•
University
28 questions
AZ-900 Module 5
Quiz
•
KG - University
30 questions
UJIAN MID SMSTR 1 XI RPL PEMROGRAMAN WEB DAN PERANGKAT BERGERAK
Quiz
•
University
30 questions
GIS IAT - 3 MCQ TEST
Quiz
•
University
Popular Resources on Wayground
10 questions
Honoring the Significance of Veterans Day
Interactive video
•
6th - 10th Grade
9 questions
FOREST Community of Caring
Lesson
•
1st - 5th Grade
10 questions
Exploring Veterans Day: Facts and Celebrations for Kids
Interactive video
•
6th - 10th Grade
19 questions
Veterans Day
Quiz
•
5th Grade
14 questions
General Technology Use Quiz
Quiz
•
8th Grade
25 questions
Multiplication Facts
Quiz
•
5th Grade
15 questions
Circuits, Light Energy, and Forces
Quiz
•
5th Grade
19 questions
Thanksgiving Trivia
Quiz
•
6th Grade
Discover more resources for Computers
20 questions
Definite and Indefinite Articles in Spanish (Avancemos)
Quiz
•
8th Grade - University
7 questions
Force and Motion
Interactive video
•
4th Grade - University
9 questions
Principles of the United States Constitution
Interactive video
•
University
18 questions
Realidades 2 2A reflexivos
Quiz
•
7th Grade - University
10 questions
Dichotomous Key
Quiz
•
KG - University
25 questions
Integer Operations
Quiz
•
KG - University
7 questions
What Is Narrative Writing?
Interactive video
•
4th Grade - University
20 questions
SER vs ESTAR
Quiz
•
7th Grade - University
