if Statements MCQ Practice

Question 1 of 10

A greenhouse mister runs when the air is dry. What text does this Java code display?

int humidity = 55;
if (humidity < 60)
    System.out.print("mist");
System.out.print("log");
  1. A. log
  2. B. mistlog
  3. C. mist
  4. D. nothing

Question 2 of 10

The mister checks a wetter reading. What text does this Java code display?

int humidity = 72;
if (humidity < 60)
    System.out.print("mist");
System.out.print("log");
  1. A. mistlog
  2. B. mist
  3. C. nothing
  4. D. log

Question 3 of 10

A ferry line uses two-way selection for wait time. What text does this Java code display?

int wait = 12;
if (wait <= 10)
    System.out.print("board");
else
    System.out.print("hold");
  1. A. hold
  2. B. board
  3. C. boardhold
  4. D. 12

Question 4 of 10

A studio clock stores whether a session started late. What text does this Java code display?

boolean late = false;
if (late)
    System.out.print("rush");
else
    System.out.print("calm");
  1. A. rush
  2. B. false
  3. C. calm
  4. D. rushcalm

Question 5 of 10

A bakery counter uses an unbraced if. What value does this Java code display?

int loaves = 3;
if (loaves >= 8)
    loaves = loaves - 3;
    loaves = loaves + 1;
System.out.print(loaves);
  1. A. 4
  2. B. 3
  3. C. 1
  4. D. 0

Question 6 of 10

The bakery runs the same unbraced updates with more loaves. What value does this Java code display?

int loaves = 10;
if (loaves >= 8)
    loaves = loaves - 3;
    loaves = loaves + 1;
System.out.print(loaves);
  1. A. 7
  2. B. 10
  3. C. 8
  4. D. 11

Question 7 of 10

A kiln schedule compares a truncated quotient. What text does this Java code display?

int clay = 19;
if (clay / 5 > 3)
    System.out.print("fire");
else
    System.out.print("add");
  1. A. fire
  2. B. add
  3. C. fireadd
  4. D. 3

Question 8 of 10

A trail map copies one count when the sides differ. What text does this Java code display?

int north = 8;
int south = 5;
if (north != south)
    north = south;
else
    south = 0;
System.out.print(north);
System.out.print(south);
  1. A. 80
  2. B. 85
  3. C. 00
  4. D. 55

Question 9 of 10

Which statement correctly describes one-way selection with if and no else?

  1. A. The body runs only when the condition is true; there is no else body.
  2. B. The body always runs, and then the condition is checked.
  3. C. The else body runs when the condition is true.
  4. D. The if body and an else body both run every time.

Question 10 of 10

A museum tag uses two separate if statements. What value does this Java code display?

int year = 1920;
int tag = 5;
if (year < 2000)
    tag = tag + 2;
if (year < 1900)
    tag = tag + 4;
System.out.print(tag);
  1. A. 11
  2. B. 5
  3. C. 7
  4. D. 9