Assignemnt #35
Code
///Colin Hinton
///5th Period
///Else If
///ElseIf.java
///9/30/2015
public class ElseIf
{
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." );
}
// by removing the else if that was here brfore we have now created a situation so that there are no longer three options
only two. This makes the program different because if there were more people than cars it would no longer default to the
deleted statement of "We should not take the cars." because it has been removed. It will now go to the next else
statement which is we cant decide.
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." );
}
}
}
// The Else If is a backup plan persay on the program. it's declaring a different program function to be executed in the if
statement if the one before it fails. So In the first one if there are more people than cars then the equation is false, so
the program moves on to the next else sttement now trying to see if there are more cars than people. And finally if that is
to also fail because the values are equal then the program is to go to its final form which consist of a final output if the
other two are failures.
Picture of the output