Assignment #35 Else And If
Code
/// Name: Matthew Lorence
/// Period: 5
/// Program Name: Else And If
/// File Name: ElseAndIf.java
/// Date Finished:10/26/15
public class ElseAndIf
{
public static void main( String[] args )
{
/// Else if prints out only the command in the else if statement if the if statement before it is false.
/// If the if statements and else if statements are false, only the command in the else prints.
/// Getting rid of the else in front of the if makes the else line print if the line above it is false.
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." );
}
}
}
Picture of the output