Assignemnt #35: Else And If

Code

    /// Name: Kelsey Lieberman
    /// Period 5
    /// Program Name: ElseAndIf
    /// File Name: ElseAndIf.java
    /// Date Finished: 10/14/2015
    
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." );
		}
	}
}
/// "else if" is a conditional that applies and runs a statement only if the first conditional is not true and its own conditional is true. "else" is a function that runs a statement if the previous conditional(s) is/are untrue /// 
        
/// removing the "else" in front of the "else if" on line 13 made it so that the else line on line 17 was displayed because the if statement was not true. The else if made it so that line is only displayed if the conditional above is untrue, and an else statement after an else if statement is only displayed if the if statement and the else if statement are untrue.///

    

Picture of the output

Assignment 35