Assignment 35
public class ElseAndIf
{
public static void main( String[] args )
{
int people = 30;
int cars = 40;
int buses = 15;
// The "else" statements trigger the code in brackets if the previous "if" or "else if" statement was not triggered
//The "else if" statements trigger if the previous "if" statement or "else if" statement did not trigger and anoter given condition is true
if ( cars > people )
{
System.out.println( "We should take the cars." );
}
else 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." );
}
}
}v