Assignment #36

Code

/// Name: Kabir Virk
/// Period: 6
/// Program Name: IfAge
/// File Name: IfAge.java
/// Date Finished: 10/15/2015
    
    public class ElseAndIf
    
    {
    	public static void main( String[] args )
    	{
    		int people = 30;
    		int cars = 40;
    		int buses = 15;
    
            //else if is an alternative if statement and else is used when neither if is true or false
            //removing the else in else if changes the parameters of the else statement following it
            //else executes if the statement before is false
            
    		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." );
    		}
    
    	}
    }
 

Picture of the output

Assignment 35