wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Quiz 3

Total questions: 51

Worksheet time: 26mins

Name
Class
Date
1.

What are the main types of operators in Java?

a)

Arithmetic, Assignment, Relational, Logical, Unary

b)

Addition, Subtraction, Multiplication, Division, Modulus

c)

If, Else, For, While, Switch

d)

Class, Object, Method, Variable

2.

Which is an example of an arithmetic operator in Java?

a)

+ (addition)

b)

= (assignment)

c)

== (equals)

d)

&& (and)

3.

What does the assignment operator = do in Java?

a)

Adds two numbers

b)

Stores a value in a variable (e.g., x = 5)

c)

Checks if two values are equal

d)

Increases a value by 1

4.

Which relational operator checks if one value is greater than another?

a)

>

b)

+=

c)

!

d)

||

5.

What does the logical operator && mean in Java?

a)

Or

b)

And

c)

Not

d)

Equals

6.

Which is a unary operator in Java (works on one value)?

a)

++ (increment)

b)

== (equals)

c)

&& (and)

d)

= (assignment)

7.

Which arithmetic operator gives the remainder of division in Java?

a)

% (modulus)

b)

/ (division)

c)

* (multiplication)

d)

- (subtraction)

8.

What does x += 3 mean in Java?

a)

Add 3 to x and store in x

b)

Check if x is equal to 3

c)

Subtract 3 from x

d)

Multiply x by 3

9.

Which relational operator checks if two values are not equal?

a)

!=

b)

==

c)

&&

d)

=

10.

What is the result of true || false in Java?

a)

true

b)

false

c)

error

d)

1

11.

What does the unary operator ++ do?

a)

Increases a value by 1

b)

Decreases a value by 1

c)

Checks if true

d)

Assigns a value

12.

What are arithmetic operators in Java?

a)

Symbols used to perform math operations like addition (+) and subtraction (-) on numbers

b)

Symbols that assign values to variables, like =

c)

Symbols that compare values, like ==

d)

Symbols that combine true/false conditions, like &&

13.

What are assignment operators in Java?

a)

Symbols that compare two values, like > or <

b)

Symbols that store a value into a variable, like = or +=

c)

Symbols that work on a single value, like !

d)

Symbols that perform logic on booleans, like ||

14.

What are relational operators in Java?

a)

Symbols used to compare two values and return true or false, like == or !=

b)

Symbols that add or multiply numbers, like *

c)

Symbols that assign values, like -=

d)

Symbols that reverse a boolean, like !

15.

What are logical operators in Java?

a)

Symbols that perform math on numbers, like /

b)

Symbols that combine or modify boolean values, like && (and) or || (or)

c)

Symbols that check equality, like ==

d)

Symbols that store data, like =

16.

What are unary operators in Java?

a)

Symbols that operate on two values, like + for addition

b)

Symbols that operate on a single value, like ++ (increment)

c)

Symbols that assign values, like +=

d)

Symbols that compare values, like >=

17.

What does operator precedence mean in Java?

a)

The speed at which operators run

b)

The order in which operators in an expression are evaluated (higher first)

c)

How many operators you can use in one line

d)

The type of data operators can work on

18.

How is Java's operator precedence similar to PEMDAS in math?

a)

Both only apply to arithmetic operators like + and *

b)

Both determine the order of evaluation, but Java includes all operators (arithmetic, logical, etc.)

c)

PEMDAS is for Java code, while operator precedence is for math

d)

They are completely different

19.

What is the value of y?
(Using pre-increment: ++x increases x first, then uses the new value)

a)

y = 8

b)

y = 7

c)

y = 5

d)

y = 10

20.

What is the value of x?

a)

5

b)

6

c)

4

d)

10

21.

What is the value of x?

a)

20

b)

25

c)

15

d)

12

22.

What is the value of x?

a)

1

b)

25

c)

20

d)

15

23.

What is the value of y?

a)

1

b)

2

c)

3

d)

4

24.

What is the value of z?

a)

false

b)

true

c)

tralse

d)

3.14

25.

What is the value z?

a)

true

b)

false

c)

tralse

d)

3.14

26.

What is the value of z?

a)

true

b)

false

c)

tralse

d)

3.14

27.

What is the value of z?

a)

true

b)

false

c)

tralse

d)

3.14

28.

What is the value of z?

a)

true

b)

false

c)

tralse

d)

3.14

29.

What is the value of z?

a)

true

b)

false

c)

tralse

d)

3.14

30.

What is the value of z?

a)

30

b)

32

c)

28

d)

2

31.

What is the result?

a)

30

b)

32

c)

28

d)

2

32.

What does the if statement do in Java?

a)

Repeats code multiple times

b)

Checks a condition and runs code only if it's true

c)

Always runs the code inside it

d)

Stops the program

33.

What happens if the condition in an if statement is false?

a)

The code inside runs anyway

b)

The code inside is skipped

c)

The program throws an error

d)

It automatically runs an else block

34.

What is the purpose of the else part in an if-else statement?

a)

To check another condition

b)

To run code if the if condition is false

c)

To repeat the if code

d)

To end the program

35.

In an if-else-if ladder, what happens after the first true condition is found?

a)

It checks all remaining conditions

b)

It skips the rest and executes only that block

c)

It runs the else block

d)

It restarts from the top

36.

What is the main purpose of this Java code?

a)

Prints even numbers from 1 to 15

b)

Prints "Fizz" for multiples of 3, "Buzz" for multiples of 5, "FizzBuzz" for both, and the number otherwise

c)

Adds numbers from 1 to 15 and prints the sum

d)

Checks if 15 is divisible by 3 or 5

37.

What does the code print when i=15?

a)

15

b)

Fizz

c)

Buzz

d)

FizzBuzz

38.

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.

a)

True

b)

False

39.

What is the main purpose of a switch statement in Java?

a)

To loop through code a set number of times

b)

To check multiple possible values of a variable and execute different code for each

c)

To check if a condition is true or false

d)

To define a new method

40.

What happens if you forget a break statement in a switch case?

a)

The program throws an error

b)

Only that case runs

c)

It "falls through" and runs the next cases until a break or end

d)

The default case always runs

41.

What is the role of the default case in a switch statement?

a)

It runs first before any other cases

b)

It runs if no other case matches the value

c)

It is required in every switch

d)

It replaces the break statement

42.

What is the result?

a)

Its apple

b)

Its banana

c)

Its orange

d)

unkown

43.

What is the purpose of loops in Java?

a)

To make decisions based on conditions

b)

To repeat a block of code multiple times while a condition is true or for a set number of times

c)

To define classes and objects

d)

To handle errors

44.

Which of the following are the main types of loops in Java?

a)

if, else, switch

b)

for, while, do-while

c)

public, static, void

d)

int, char, String

45.

What is the basic structure of a for loop in Java?

a)

for (initialization; condition; update) { code; }

b)

for { code; } (condition)

c)

if (condition) { code; }

d)

while (initialization) { code; }

46.

When is a while loop best used in Java?

a)

When you know exactly how many times to repeat (like for)

b)

When the number of repetitions is unknown, but depends on a condition checked before each run

c)

For checking multiple exact values like switch

d)

Only for arrays

47.

What causes an infinite while loop?

a)

Forgetting to update the loop variable inside the body

b)

Using break statement

c)

Having a false condition

d)

Using do-while instead

48.

What makes do-while different from while in Java?

a)

Do-while checks the condition after running the code at least once

b)

Do-while can only run once

c)

Do-while doesn't need a condition

d)

Do-while is the same as for

49.

What does break do in a loop?

a)

Skips the rest of the current iteration and goes to the next

b)

Exits the loop entirely

c)

Restarts the loop from the beginning

d)

Prints a message

50.

What does the continue keyword do in a Java loop?

a)

Exits the loop entirely

b)

Skips the remaining code in the current iteration and starts the next iteration

c)

Restarts the loop from the beginning

d)

Prints a message and continues

51.

Who is the father of Java?

a)
James Gosling
b)
Elon Musk
c)
Bill Gates
d)
Mark Zuckerberg