Homework Clinic

Science Clinic => Computer Science => Topic started by: washai on May 6, 2020

Title: Suppose isPrime is a boolean variable, which of the following is the correct and best statement for ...
Post by: washai on May 6, 2020

Question 1

Analyze the following code:

boolean even = false;
if (even = true) {
System.out.println("It is even!");
}

◦ The program runs fine and displays It is even!
◦ The program has a runtime error.
◦ The program has a compile error.
◦ The program runs fine, but displays nothing.

Question 2

Suppose isPrime is a boolean variable, which of the following is the correct and best statement for testing if isPrime is true?
◦ if (isPrime = true)
◦ if (isPrime)
◦ if (!isPrime = false)
◦ if (isPrime == true)
◦ if (!isPrime == false)
Title: Suppose isPrime is a boolean variable, which of the following is the correct and best statement for ...
Post by: chereeb on May 6, 2020

Answer 1

The program runs fine and displays It is even!

Answer 2

if (isPrime)
Title: Re: Suppose isPrime is a boolean variable, which of the following is the correct and best statement
Post by: KHADKAG on Oct 18, 2021
idk