Search Header Logo

Java-If - If/Else

Authored by Jessica Horning

Computers

9th - 12th Grade

Used 71+ times

Java-If - If/Else
AI

AI Actions

Add similar questions

Adjust reading levels

Convert to real-world scenario

Translate activity

More...

    Content View

    Student View

10 questions

Show all answers

1.

MULTIPLE CHOICE QUESTION

1 min • 1 pt

Java supports six relational operators that are used to make comparisons: =, <, >, <=, >=, =!

True
False

2.

MULTIPLE CHOICE QUESTION

1 min • 1 pt

Is this code segment is correct?
if(quizScore == 10)
System.out.println("Perfect score");

Yes
No

3.

MULTIPLE CHOICE QUESTION

2 mins • 1 pt

WHICH TYPE OF DECISION STRUCTURE IS THIS?
if (x==10)
{
          if (y==20)
          {
                    System.out.println("Coordinates: 10, 20");
          }
}

Switch
If Else if 
If else (binary choice)
Nested If

4.

MULTIPLE CHOICE QUESTION

1 min • 1 pt

Of the following if statements, which one correctly executes three instructions if the condition is true?

if (x < 0)  
a = b * 2;
 
y = x;
 
 z = a – y;
{
   if (x <0)
   a = b*2;
   y=x;
   z=a-y;
}
if { (x < 0) 
a = b * 2;  
y = x;  
 z = a – y;
}
if (x <0)
{
a = b*2;
y = x;
z = a - y;
}

5.

MULTIPLE CHOICE QUESTION

1 min • 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--;
else x = 0;
if (x == 0) x = 0;
else x++;
x--;

6.

MULTIPLE CHOICE QUESTION

1 min • 1 pt

Media Image

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

7.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

IF Score > Highest THEN

PRINT “NEW WORLD RECORD!”

ELSE

IF Score < Highest + 10 THEN

PRINT “GOOD PERFORMANCE”

ELSE

PRINT “AVERAGE PERFORMANCE”

END IF

END IF

If Score equals 130 and Highest equals 120, what is the output?

NEW WORLD RECORD!

AVERAGE RACE

GOOD RACE

No output.

Access all questions and much more by creating a free account

Create resources

Host any resource

Get auto-graded reports

Google

Continue with Google

Email

Continue with Email

Classlink

Continue with Classlink

Clever

Continue with Clever

or continue with

Microsoft

Microsoft

Apple

Apple

Others

Others

Already have an account?