Assignment #35

Code

    ///Name: Cody Swain
    ///Period: 6
    ///Project Name: ElseAndIf
    ///File Name: ElseAndIf.java
    ///Date: 10/13/15
    
    public class ElseAndIf
    {
        public static void main( String[] args )
        {
            int people = 30;
            int cars = 40;
            int buses = 15;
            
            if ( cars > people )
            {
                System.out.println( "We should take the cars." );
            }
            if ( cars < people )
            {
                System.out.println( "We should not take the cars." );
            }
            else
            {
                System.out.println( "We can't decide." );
            }
            
            
            if (buses > cars )
            {
                System.out.println( "That's too many buses." );
            }
            else if ( buses < cars )
            {
                System.out.println( "Maybe we could take the buses." );
            }
            else 
            { 
                System.out.println( "we still can't decide." );
            }
            
            if ( people > buses )
            {
                System.out.println( "All right, let's just take the buses." );
            }
            else
            {
                System.out.println( "Fine, let's stay home then." );
            }
        }
    }
    
    
    /* 
    
    1. The (ELSE IF) statement is only checked if the first (IF) statement is false. So if the first (IF) statement is false, it will then check the (ELSE IF) statement to check if it is true. If the (ELSE IF) one is true, then it will execute the statement under it. The else statement executes its statement only if the (IF) and (ELSE IF) are both false. 
    
    2. By removing the ELSE from the first else if statement, it turns it into an if statement. Then it evalutes the if statement and if it is false it will execute the else statement. The else statement wouldn't execute if the ELSE was still there and it was a true statement. 
    
    */
    


        
    

Picture of the output

Assignment 35