Assignment #35 Else If
Code
///Name: Ian Grant
///Period:5
///Project Name: Else If
///File Name:ElseIf.java
///10/19/15
public class ElseIf
{
public static void main(String[] args)
{
//Else if runs if the if statement is false and the else statement runs if all else statments are false.
//When the else in elseif is removed it becomes another if statment that runs with the other if statement
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("Thats to 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 than.");
}
}
}
Output