Assignment #35 and Else and If
Code
/// Name: Lauren Baird
/// Period: 7
/// Program Name: Else and If
/// File Name: ElseAndIf.java
/// Date Finished: 10/07/15
public class ElseAndIf
{
public static void main( String[] args )
{
int people = 30;
int cars = 40;
int buses = 15;
// "else if" is used when the "if" statement is incorrect. "else" is used when both the "else if" and the "if" statements are incorrect.
// removing the "else" from on of the "else if" statements changes what will print.
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 them." );
}
}
}
Picture of the output