NOT!

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.
go to previous page   go to home page   hear noise   go to next page

Answer:

5 > 2 || 12 <= 7     T  
5 > 2 && 12 <= 7     F  
3 == 8 || 6 != 6     F  
3 == 8 && 6 != 6     F  

NOT!

The NOT operator in Java is this:   !   (exclaimation point). The NOT operator changes true to false and false to true, as seen in the truth table. This may seem like a silly thing to do, but often it is useful. Sometimes it is more natural to express a condition in a particular way, but the program logic calls for the reverse of what you have written. Time for the NOT operator.

A!A
truefalse
falsetrue

Say that you are shopping for new shoes. You are only interested in shoes that cost less than $50. Here is a program fragment:

if (  ______(cost < 50)  )
  System.out.println("Reject these shoes");
else
  System.out.println("Acceptable shoes");

QUESTION 22:

Fill in the blank so that the program fragment rejects shoes that do not cost less than $50.