NEW
Font size
WorksheetsQuiz 3
Total questions: 51
Worksheet time: 26mins
What are the main types of operators in Java?
Arithmetic, Assignment, Relational, Logical, Unary
Addition, Subtraction, Multiplication, Division, Modulus
If, Else, For, While, Switch
Class, Object, Method, Variable
Which is an example of an arithmetic operator in Java?
+ (addition)
= (assignment)
== (equals)
&& (and)
What does the assignment operator = do in Java?
Adds two numbers
Stores a value in a variable (e.g., x = 5)
Checks if two values are equal
Increases a value by 1
Which relational operator checks if one value is greater than another?
>
+=
!
||
What does the logical operator && mean in Java?
Or
And
Not
Equals
Which is a unary operator in Java (works on one value)?
++ (increment)
== (equals)
&& (and)
= (assignment)
Which arithmetic operator gives the remainder of division in Java?
% (modulus)
/ (division)
* (multiplication)
- (subtraction)
What does x += 3 mean in Java?
Add 3 to x and store in x
Check if x is equal to 3
Subtract 3 from x
Multiply x by 3
Which relational operator checks if two values are not equal?
!=
==
&&
=
What is the result of true || false in Java?
true
false
error
1
What does the unary operator ++ do?
Increases a value by 1
Decreases a value by 1
Checks if true
Assigns a value
What are arithmetic operators in Java?
Symbols used to perform math operations like addition (+) and subtraction (-) on numbers
Symbols that assign values to variables, like =
Symbols that compare values, like ==
Symbols that combine true/false conditions, like &&
What are assignment operators in Java?
Symbols that compare two values, like > or <
Symbols that store a value into a variable, like = or +=
Symbols that work on a single value, like !
Symbols that perform logic on booleans, like ||
What are relational operators in Java?
Symbols used to compare two values and return true or false, like == or !=
Symbols that add or multiply numbers, like *
Symbols that assign values, like -=
Symbols that reverse a boolean, like !
What are logical operators in Java?
Symbols that perform math on numbers, like /
Symbols that combine or modify boolean values, like && (and) or || (or)
Symbols that check equality, like ==
Symbols that store data, like =
What are unary operators in Java?
Symbols that operate on two values, like + for addition
Symbols that operate on a single value, like ++ (increment)
Symbols that assign values, like +=
Symbols that compare values, like >=
What does operator precedence mean in Java?
The speed at which operators run
The order in which operators in an expression are evaluated (higher first)
How many operators you can use in one line
The type of data operators can work on
How is Java's operator precedence similar to PEMDAS in math?
Both only apply to arithmetic operators like + and *
Both determine the order of evaluation, but Java includes all operators (arithmetic, logical, etc.)
PEMDAS is for Java code, while operator precedence is for math
They are completely different
What is the value of y?
(Using pre-increment: ++x increases x first, then uses the new value)
y = 8
y = 7
y = 5
y = 10
What is the value of x?
5
6
4
10
What is the value of x?
20
25
15
12
What is the value of x?
1
25
20
15
What is the value of y?
1
2
3
4
What is the value of z?
false
true
tralse
3.14
What is the value z?
true
false
tralse
3.14
What is the value of z?
true
false
tralse
3.14
What is the value of z?
true
false
tralse
3.14
What is the value of z?
true
false
tralse
3.14
What is the value of z?
true
false
tralse
3.14
What is the value of z?
30
32
28
2
What is the result?
30
32
28
2
What does the if statement do in Java?
Repeats code multiple times
Checks a condition and runs code only if it's true
Always runs the code inside it
Stops the program
What happens if the condition in an if statement is false?
The code inside runs anyway
The code inside is skipped
The program throws an error
It automatically runs an else block
What is the purpose of the else part in an if-else statement?
To check another condition
To run code if the if condition is false
To repeat the if code
To end the program
In an if-else-if ladder, what happens after the first true condition is found?
It checks all remaining conditions
It skips the rest and executes only that block
It runs the else block
It restarts from the top
What is the main purpose of this Java code?
Prints even numbers from 1 to 15
Prints "Fizz" for multiples of 3, "Buzz" for multiples of 5, "FizzBuzz" for both, and the number otherwise
Adds numbers from 1 to 15 and prints the sum
Checks if 15 is divisible by 3 or 5
What does the code print when i=15?
15
Fizz
Buzz
FizzBuzz
True or False: If you remove the "&& i % 5 == 0" from the first if condition, the code will still print "FizzBuzz" for multiples of 15.
True
False
What is the main purpose of a switch statement in Java?
To loop through code a set number of times
To check multiple possible values of a variable and execute different code for each
To check if a condition is true or false
To define a new method
What happens if you forget a break statement in a switch case?
The program throws an error
Only that case runs
It "falls through" and runs the next cases until a break or end
The default case always runs
What is the role of the default case in a switch statement?
It runs first before any other cases
It runs if no other case matches the value
It is required in every switch
It replaces the break statement
What is the result?
Its apple
Its banana
Its orange
unkown
What is the purpose of loops in Java?
To make decisions based on conditions
To repeat a block of code multiple times while a condition is true or for a set number of times
To define classes and objects
To handle errors
Which of the following are the main types of loops in Java?
if, else, switch
for, while, do-while
public, static, void
int, char, String
What is the basic structure of a for loop in Java?
for (initialization; condition; update) { code; }
for { code; } (condition)
if (condition) { code; }
while (initialization) { code; }
When is a while loop best used in Java?
When you know exactly how many times to repeat (like for)
When the number of repetitions is unknown, but depends on a condition checked before each run
For checking multiple exact values like switch
Only for arrays
What causes an infinite while loop?
Forgetting to update the loop variable inside the body
Using break statement
Having a false condition
Using do-while instead
What makes do-while different from while in Java?
Do-while checks the condition after running the code at least once
Do-while can only run once
Do-while doesn't need a condition
Do-while is the same as for
What does break do in a loop?
Skips the rest of the current iteration and goes to the next
Exits the loop entirely
Restarts the loop from the beginning
Prints a message
What does the continue keyword do in a Java loop?
Exits the loop entirely
Skips the remaining code in the current iteration and starts the next iteration
Restarts the loop from the beginning
Prints a message and continues
Who is the father of Java?
