Assignemnt #35
Code
/// Name: Ryan Volko
/// Period: 7
/// Program Name: Else And If Program
/// File Name: ElseAndIf.java
/// Date Finished: 10/7/2015
public class ElseAndIf
{
public static void main( String[] args )
{
//else if line is printed if the if line is flase and else if is true, else is only printed if else if and if are false.
//the else line could not print as it needs the else if line to be false and there is no else if line. It also didn't complie.
int people = 30;
int cars = 40;
int buses = 15;
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." );
}
}
}
Picture of the output