Assignment #33: What If

Code

/// Name: Kiran O'Farrell
/// Period: 7
/// Program name: What If
/// File Name: IfDecisions.java
/// Date Finished: 9/28/15

public class IfDecisions {

    public static void main (String[] args) {
    
        int people = 30;
        int cats = 10;
        int dogs = 10;
        
        if (people < cats) {
        
        System.out.println("Too many cats! The world is doomed!");
        
        }
        
        if (people > cats) {
        
        System.out.println("Not many cats! The world is saved!");
        
        }
        
        if (people < dogs) {
        
        System.out.println("The world is drooled on!");
        
        }
        
        if (people > dogs) {
        
        System.out.println("The world is dry!");
        
        }
        
        dogs += 5;
        
        if (people < dogs) {
        
        System.out.println("There are fewer people than dogs.");
        
        }
        
        if (people > dogs) {
        
        System.out.println("There are fewer dogs than people.");
        
        }
        
        if (people == dogs) {
        
        System.out.println("There are equal numbers of dogs and people.");
        
        }
        
    }
    
}
    

Picture of the output

Assignment 33

Notes:

The "if" statement causes the code contained in it to only trigger when a certain condition is fulfilled. The curly braces control which code is controlled by the condition (in this case, printing the messages). Setting the number of people equal to the number of cats would cause neither condition to be fulfilled, and therefore, neither message would be printed.