Preview

20 - Equivalent Boolean Expressions

 1. The "less than or equal to" comparison operator in Java is __________.

  <=

  !=

  <<

  <

 2. The equal comparison operator in Java is __________.

  !=

  Single equals sign: =

  Double equals sign, ==

  <>

 3. What is 1 + 1 + 1 + 1 + 1 == 5?

  0

  TRUE

  FALSE

  Error

 4. What is 1 - 0.1 - 0.1 - 0.1 - 0.1 - 0.1 == 0.5?

  Floating poing numbers are approximations so there is no guarantee of this being true.

  FALSE

  TRUE

  Error

 5. In Java, the word "true" is ________.

  a Java keyword

  same as value 0

  a Boolean literal

  same as value 1

 6. Which of the following code displays the area of a circle if the radius is positive?

  if (radius != 0) System.out.println(radius * radius * 3.14159);

  if (radius >= 0) System.out.println(radius * radius * 3.14159);

  if (radius <= 0) System.out.println(radius * radius * 3.14159);

  if (radius > 0) System.out.println(radius * radius * 3.14159);

 7. What is the output of the following code?
int x = 0;
if (x < 4) {
  x = x + 1;
}
System.out.println("x is " + x);

  x is 1

  x is 2

  x is 3

  x is 0

 8. If the income is 4001, what is the output of the following code?
if (income > 3000) {
  System.out.println("Income is greater than 3000");
}
else if (income > 4000) {
  System.out.println("Income is greater than 4000");
}

  Income is greater than 4000

  No output

  Income is greater than 3000

  Income is greater than 3000 followed by income is greater than 4000

 9. 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 = false)

  if (isPrime)

  if (isPrime == true)

 10. The result of fruit1.equals(fruit2) is the boolean value false.
String fruit1 = "Apple";
String fruit2 = "Orange";
System.out.println(fruit1.equals(fruit2));

  True

  False