Assignemnt #35: Else And If Statements
Code
/// Name: Sean Harrison
/// Period: 7
/// Program name: Else and if Statements
/// File Name: ElseAndIf.java
/// Date Finished: 10/6/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." );
}
}
}
/// I think the else if, and else are backups if the statement is false. It's a fallback to display something even if a statement would initally be hidden.
/// When else was removed, there is one less option for the program to fall back onto, leading to a greater likelyhood of nothing being displayed at all.
Picture of the output