go to previous page   go to home page   go to next page hear noise highlighting

Answer:

No.


Car Purchase Decision

You need money OR credit. Just one would be enough. Of course, if you had lots of money and plenty of credit you could certainly buy the car.

Sometimes a program has to test if one or the other (or both) of the conditions has been met. Here is how that is done with the car purchase problem:


How much cash do you have?    

How much credit do you have?  

  if ( cash>=25000 ||  credit>=25000 )
    System.out.println("Enough to buy this car!");
  else
    System.out.println("Have you considered a Yugo?");


  

The symbol || (vertical-bar vertical-bar) means OR. On your keyboard, vertical-bar is the top character on the key above the "enter" key. The OR operator evaluates to true when either qualification is met or when both are met. The if statement asks a question with two parts:

if ( cash >= 25000 ||  credit >= 25000  )
     -------------      -------------
       cash part         credit part

If either part is true, or both parts are true, then the entire boolean expression is true.


QUESTION 17:

Say that you enter 56000 for cash and 0 for credit. What answer (true or false) does each part give you?

               
cash  >= 25000  

credit >= 25000  

What does the entire boolean expression give you?

               
cash  >= 25000 || credit >= 25000  

go to previous page   go to home page   go to next page