Understanding If Statements in Java

Understanding If Statements in Java

5th Grade

15 Qs

quiz-placeholder

Similar activities

Coding Basics

Coding Basics

5th - 8th Grade

20 Qs

Repaso de Objetos en Java

Repaso de Objetos en Java

5th Grade

12 Qs

Что мы помним по разработке бота дискорд?

Что мы помним по разработке бота дискорд?

1st - 5th Grade

13 Qs

MINECRAT: Learn and have fun

MINECRAT: Learn and have fun

5th - 7th Grade

13 Qs

Javascript

Javascript

KG - Professional Development

13 Qs

Math Project for Equations and Inequalities

Math Project for Equations and Inequalities

5th - 7th Grade

20 Qs

Java Web

Java Web

1st - 7th Grade

12 Qs

Understanding If Statements in Java

Understanding If Statements in Java

Assessment

Quiz

Computers

5th Grade

Hard

Created by

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

Create resources
Host any resource
Get auto-graded reports
or continue with
Microsoft
Apple
Others
By signing up, you agree to our Terms of Service & Privacy Policy
Already have an account?