Nested If Statements Worksheet Answers

1.  10  5

2.  (nothing is printed)

3.  5  10

4.  5  8

5.  0  13

6.  2  5  8

7.  20  5  15

8.  -1

9.  System.out.println("Enter your age: ");
    age = keyboard.nextInt();
    if (age >= 21)
       System.out.println("You are old enough to drink\n");
    else
       System.out.println("You are not old enough to drink\n");

10. System.out.println("Enter your age: ");
    age = keyboard.nextInt();
    if (age < 17)
       System.out.println("You are not old enough to drive\n");
    else
       if (age < 21)
          System.out.println("You are old enough to drive but too young to drink\n");
       else
          System.out.println("You are old enough to drive and old enough to drink\n");


11. System.out.println("Enter the temperature: ";
    temperature = keyboard.nextInt();
    if (temperature > 83)
       System.out.println("hot");
    else if (temperature >= 68)
       System.out.println("ideal");
    else if (temperature >= 45)
       System.out.println("cool");
    else
       System.out.println("cold");

Email Me | Office Hours | My Home Page | Department Home | MCC Home Page

© Copyright Emmi Schatz 2013