No. You need 4 cups of flour and 2 cups of sugar. Now you have more than enough flour, but not enough sugar, so you can't follow the recipe.
In order to bake cookies two things must be true:
If one of these requirements is false, then you do not have enough ingredients. Here is a program that follows this logic (I hope I don't need to remind you to copy it and to play with it):
// Cookie Ingredients Checker
//
import java.io.*;
class CookieChecker
{
public static void main (String[] args) throws IOException
{
BufferedReader stdin =
new BufferedReader ( new InputStreamReader( System.in ) );
String inData;
int sugar, flour;
// get the number of cups of flour
System.out.println("How much flour do you have?");
inData = stdin.readLine();
flour = Integer.parseInt( inData );
// get the number of cups of sugar
System.out.println("How much sugar do you have?");
inData = stdin.readLine();
sugar = Integer.parseInt( inData );
// check that there are enough of both ingredients
if ( flour >= 4 && sugar >= 2 )
System.out.println("Enough for cookies!" );
else
System.out.println("sorry...." );
}
}
The symbol in Java that means "and" is "&&" (ampersand ampersand).
The if
statement is asking a question with two parts:
if ( flour >= 4 && sugar >= 2 )
---------- ----------
flour part sugar part
Each one of these parts is a relational expression. A relational expression is a type of boolean expression that uses a relational operator to compute a true or false value. The entire expression between parentheses is also a boolean expression. It is correct (and common) for a boolean expression to be composed of smaller boolean expressions. This is similar to human language where "compound sentences" are made from smaller sentences.