Preview

19 - Compound Boolean Expressions

 1. Assuming you have declared the following two variables, what is the outcome of i==j?
int i = 5;
int j = 10;

  FALSE

  TRUE

 2. The values of i and n after the code is executed are as follows: i is 0, and n is 11.
int i = 10;
int n = i++%5;

  False

  True

 3. You can combine two or more relational expressions in a single Boolean expression by using __________ operators.

  arithmetic

  logical

  mystical

  constant

 4. For complicated Boolean expressions you can use parentheses to group things, and you use the symbols && to mean ?AND? and the symbols || to mean _____.

  "NOR"

  "NOT"

  "OR"

  "JOT"

 5. If a user entered age=40, yearly income =49000 and 7.5 for cute, what would the output be for whether or not it would be possible to date?
public class demoprogram {
 4     public static void main( String[] args ) {
 5         Scanner keyboard = new Scanner(System.in);
 6         int age;
 7         double income, cute;
 8         boolean allowed;
 9 
10         System.out.print( "Enter your age: " );
11         age = keyboard.nextInt();
12 
13         System.out.print( "Enter your yearly income: " );
14         income = keyboard.nextDouble();
15 
16         System.out.print( "How cute are you, on a scale from 0.0 to 10.0? " );
17         cute = keyboard.nextDouble();
18 
19         allowed = ( age > 25 && age < 40 && ( income > 50000 || cute >= 8.5 ) );
20 
21         System.out.println( "Allowed to date my child? " + allowed );
22     }
23 }

  TRUE

  FALSE