Assignment #33 and What If
Code
/// Name: Brendan Baird
/// Period: 6
/// Program Name: What If
/// File Name: WhatIf.java
/// Date Finished: 9/30/2015
public class WhatIf
{
public static void main( String[] args )
{
int people = 20;
int cats = 20;
int dogs = 15;
//the curly braces hold the statement so it will only run when the if statement is true
if ( people < cats )
{
System.out.println( "Too many cats! The world is doomed!" );
}
//does not print because people and cats are equal
if ( people > cats )
{
System.out.println( "Not many cats! The world is saved!" );
}
//does not print because people and cats are equal in value
if ( people < dogs )
{
System.out.println( "The world is drooled on!" );
}
//does not print because the if statement requirement is false
if ( people > dogs )
{
System.out.println( "The world is dry!" );
}
//prints because there are more people than dogs
dogs += 5;
if ( people >= dogs )
{
System.out.println( "People are greater than or equal to dogs." );
}
//prints because the value contained in dogs int increased by 5
if ( people <= dogs )
{
System.out.println( "People are less than or equal to dogs." );
}
//prints because people and dogs are now equal
if ( people == dogs )
{
System.out.println( "People are dogs." );
}
//prints because the requirement is met
}
}
Picture of the output