Assignemnt #35

Code


 /// Name: Daniel Nguyen
 /// Period: 6
 /// Program Name: ElseAndIf Program
 /// File Name: ElseAndIf.java
 /// Date Finished: 9/9/2015

// Else and if are determining what function should be brought out depending on the values of the variables, if if will not run if else will try to run and if if else fails else will run.

// Removing else will cause it to run even if the first one works or not.
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." );
		}
		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

Assignment 3
BACK HOME NEXT