by _____________________________________
Fill in the information about these decision making programs and statements:
import java.util.Scanner ;
public class CookieDecision {
public static void main (String[] args) {
Scanner scan = new Scanner( System.in );
int hunger, look, smell ;
System.out.print("How hungry are you? (1-10): ");
hunger = scan.nextInt();
System.out.print("How nice do the cookies look? (1-10): ");
look = scan.nextInt();
System.out.print("How nice do the cookies smell? (1-10): ");
smell = scan.nextInt();
if ( (hunger + look + smell ) > 15 )
System.out.println("Buy cookies!" );
System.out.println("Continue down the Mall.");
}
} |
|
Evaluate each of the following Boolean expressions (to true or false):
|
Is the following a correct if statement? _________
if ( booleanExpression ){
one or more statements
}else{
one or more statements }
|
import java.util.Scanner;
class SweaterPurchase {
public static void main (String[] args) {
final int price = 4495; // price in cents
Scanner scan = new Scanner( System.in );
int cash;
System.out.println("How much do you have, in pennies?");
cash = scan.nextInt();
if ( __________________________________________ )
System.out.println("You can buy the sweater." );
else
{
System.out.println("You can't buy the sweater." );
System.out.println("You need " + (price-cash) + " more cents." );
}
}
} |
The reserved word _________ says that the value held in price will not change during the run of the program. Why pennies? Programs that deal with financial matters frequently do their calculations using ______________. As you have seen,_____________________ is not exact. Boolean expressions are always true or false. Use the correct relational operator (==, >, <, >=, <=, != ) to ask a question that is true when you want the true branch to be executed. If the statements inside of the two branches are reversed, pick a ______________________________ so the program does the same thing as before. What is the "opposite" of <= ? ___________ |