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

An applicant must meet two conditions:

Answer:

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

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

else

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

Precedence of Logical Operators

You have seen that when expressions mix && with || that evaluation must be done in the correct order. Parentheses can be used to group operands with their correct operator, just like in arithmetic. Also like arithmetic operators, logical operators have precedence that determines how things are grouped in the absence of parentheses.

In an expression, the operator with the highest precedence is grouped with its operand(s) first, then the next highest operator will be grouped with its operands, and so on. If there are several logical operators of the same precedence, they will be examined left to right.

It is common for programmers to use parentheses to group operands together for readability even when operator precedence alone would work.

Operatorprecedence
!High
&&Medium
||Low
A || B && CmeansA || (B && C)
A && B || C && Dmeans(A && B) || (C && D)
A && B && C || Dmeans((A && B) && C) || D
!A && B || Cmeans((!A) && B) || C

QUESTION 16:

Insert parentheses into the following to show how operator precedence groups operands:


Don't change the meaning of the expression; use parentheses to make the order of evaluation clear.