Assignment 35

Code

    ///Name:Nick Quijivix
    ///Period:7
    ///Date:10/14/15
    ///The else statement works on the if statement that was printed before it. The else if statement only works when the line before it is false, same with the else statement.
    ///If I remove an else from one of the else if statements, the else statement that follows it will be printed because the previous else if statement turned out to be false, thus printing the else statement coming after due to it being false.
    
    
    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." );
    		}
    		else 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." );
    		}
    
    	}
    }
    

Picture of the output

Assignment 35