Assignemnt #35 and ElseAndIf
Code
/// name: Leila Ordukhani
/// period: 6
/// program name: Twenty-Fourth Program
/// file name: ElseAndIf.java
/// date finished: 10/13/15
import java.util.Scanner;
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 stay home then." );
}
System.out.println( "I think the else and else if are saying that it will only happen if the statement is true or else it won't" );
System.out.println( "I think removing the else means that it will happen only if it's true" );
}
}
Picture of the output