Assignment #35
Code
///Jack Newsom
///Period 5
///Program Name : ElseAndIf
///filename: ElseAndIf.java
//date completed 9/21/15
package ifStatements;
public class ElseAndIf {
public static void main(String[] args) {
//ELSE IF statements only run when the statement before is false
//ELSE statements only run if the entire proceeding IF statement is false
//only one statement within an IF ELSE statement can run
//if the programmer was to remove the ELSE in an ELSE IF statement, the new statement would be independent of earlier IF and ELSE IF statements
int people = 30, cars = 40, buses = 15;
if ( cars > people)
{
System.out.println("We should take the cars.");
}
else if ( cars < people)
{
System.out.println("We shouldn't 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 just stay home.");
}
}
}
Picture of the output