&&

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:

               
flour >= 4  true

sugar >= 2  false 

&&

Examine this part of the program:

// check that there is enough of both ingredients
if ( flour >= 4 && sugar >= 2 )
  System.out.println("Enough for cookies!" );
else
  System.out.println("sorry...." );

For you to have enough ingredients, both relational expressions must be true. This is the role of the && (and-operator) between the two relational expressions. The && requires that both

flour >= 4 

and

sugar >= 2 

are true before the entire expression is true. The entire question must be true in order for the true branch to execute.

The and operator && is a logical operator. A logical operator examines two true/false values and outputs a single true/false value.

QUESTION 4:

What is printed if the user enters 6 for flour and 4 for sugar?