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

Answer:

No, you can't buy the car (at least that is what the incorrect boolean expression says.)


Incorrect Parentheses

You have $50,000 in cash, $100,000 of credit, and $3,000 of debt. Here is how the incorrect expression is evaluated:

( cash >= 25000  ||  credit >= 25000 ) && debt < 1000 

(      true      ||  credit >= 25000)  && debt < 1000

(               true                )  && debt < 1000

                true                   &&     false

                                      false

The correctly grouped expression,

cash >= 25000  ||  ( credit >= 25000 && debt < 1000 )

immediately evaluates to true.

Here is another problem: a program screens job applicants. An applicant is accepted for an interview only if the applicant meets two conditions:


QUESTION 15:

Put parentheses in this boolean expression so that it correctly tests applicants:

if (   college >= 4   &&   experience   >= 2   ||    gpa > 3.5   )

  System.out.println("Interview applicant");

else

  System.out.println("Send resume to circular file.");