Assignment #35 and ElseAndIf
Code
/// Name: Jason Kim
/// Period: 7
/// Program Name: ElseAndIf
/// File Name: ElseAndIf.java
/// Date Finished:10/2/15
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 take the cars." );
}
else
{
System.out.println( "We can't decide." );
}
if (buses > cars)
{
System.out.println( "That's too many buses.");
}
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." );
}
}
}
///else if is used to add a condition when the "if" condition above is false.
///else is used to activate codes inside the else braces when "if" statement and "else if" statement above is false.
//If I delete "else" from "else if," else activates if the second "if" is false, regardless of the first "if."
Picture of the output