
Understanding If Statements in Java

Quiz
•
Computers
•
5th Grade
•
Hard

Mohid Atif
FREE Resource
15 questions
Show all answers
1.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What is the correct syntax for an if statement in Java?
if (condition) {}
if condition: {}
if [condition] {}
if condition {}
2.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Which of the following is used to compare two strings in Java for equality within an if statement?
==
equals()
compareTo()
Both A and B
3.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What will the following code snippet print? ```java if (5 > 3) { System.out.println("Five is greater than three."); } ```
Five is greater than three.
Error
Nothing
5 > 3
4.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
How can you correctly check if a string `name` equals "John" in an if statement?
if (name == "John")
if (name.equals("John"))
if ("John".equals(name))
B and C are correct
5.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What is the output of the following code? ```java String a = "Hello"; String b = "hello"; if (a.equals(b)) { System.out.println("Equal"); } else { System.out.println("Not Equal"); } ```
Error
Equal
Not Equal
None of the above
6.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
In Java, which operator is used to check if two values are NOT equal in an if statement?
!=
==
<=
>=
7.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What does the following code snippet output? ```java int number = 10; if (number % 2 == 0) { System.out.println("Even"); } else { System.out.println("Odd"); } ```
Odd
Even
Error
None of the above
Create a free account and access millions of resources
Similar Resources on Wayground
20 questions
Basic Python Quiz for Beginners

Quiz
•
3rd - 6th Grade
15 questions
AV1\R1 3TEC_BE_Acesso a Propriedades em JavaScript 1 a 16

Quiz
•
1st Grade - University
10 questions
Programming Concepts Quiz

Quiz
•
5th Grade
10 questions
Computer Languages

Quiz
•
KG - University
10 questions
MOBILE APPLICATION DEVELOPMENT

Quiz
•
1st - 10th Grade
15 questions
Roblox Studio concept review

Quiz
•
1st - 12th Grade
15 questions
computer language

Quiz
•
5th - 10th Grade
12 questions
Front-end quiz

Quiz
•
1st - 10th Grade
Popular Resources on Wayground
10 questions
Video Games

Quiz
•
6th - 12th Grade
10 questions
Lab Safety Procedures and Guidelines

Interactive video
•
6th - 10th Grade
25 questions
Multiplication Facts

Quiz
•
5th Grade
10 questions
UPDATED FOREST Kindness 9-22

Lesson
•
9th - 12th Grade
22 questions
Adding Integers

Quiz
•
6th Grade
15 questions
Subtracting Integers

Quiz
•
7th Grade
20 questions
US Constitution Quiz

Quiz
•
11th Grade
10 questions
Exploring Digital Citizenship Essentials

Interactive video
•
6th - 10th Grade