A good answer might be:

Yes.

Non-short-circuit Operator

  • true  && true  is true    --both operands evaluated
  • false && true  is false   --only first operand evaluated
  • true  && false is false   --both operands evaluated
  • false && false is false   --only first operand evaluated
  • true  & true  is true    --both operands evaluated
  • false & true  is false   --both operands evaluated
  • true  & false is false   --both operands evaluated
  • false & false is false   --both operands evaluated

The & operator combines two boolean values using the rules for AND, but always evaluates both operands. This is useful when you want both operands to be evaluated no matter what values are returned.

The disadvantage is a potential loss of speed. Most Java programs are written using the && operator whenever an AND is needed. The programmer must be careful of side-effects, though. Usually this is done by writing methods that are "pure functions" as much as possible. A pure function is a method that returns a value and is free of side effects. Methods that are not pure functions should usually be kept out of boolean expressions.

For example, the method computeMaximum() in the previous example is not a pure function. It would be better if it computed the maximum, but did not itself save the result. Then the program fragment could be written like this:

int maximum;
. . .

maximum = computeMaximum();

if ( sum < 100  && maximum < 500 ) 

. . .

result = 2 *  maximum ;   
Now there is no danger from side-effects and it is clear where maximum is set.

QUESTION 5:

What does the following print?

int count = 0;     // say that these values are the result of
int total = 345;   // the program running with input data.

if ( count > 0 && total / count > 80 )
  System.out.println("Acceptable Average");
else
  System.out.println("Poor Average");

Click Here after you have answered the question