Assignment #35 and Else And If
Code
///Name: Tim Gibson
///Period: 6
///Project Name: Else and If
///File Name: ElseAndIf.java
///Date Finished: 10/1/15
// I think else if says that if the first conditions aren't met but the second ones are, then do whatever is contained in the else if. I think else says if the other things aren't done, then do this thing.
//When the else is removed from the first else if, the second else happens. This is because the second else occcurs because the first one didn't.
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 just stay home then." );
}
}
}
Picture of the output