Assignemnt #33: What If Statements
Code
/// Name: Sean Harrison
/// Period: 7
/// Program name: WhatIf
/// File Name: WhatIf.java
/// Date Finished: 10/5/2015
public class WhatIf
{
public static void main( String[] args )
{
int people = 20;
int cats = 20;
int dogs = 15;
if ( people < cats )
{
System.out.println( "too many cars! The world is doomed!" );
}
if (people > cats )
{
System.out.println( "Not many cats! The world is saved!" );
}
if ( people < dogs )
{
System.out.println( "The world is drooled on!" );
}
if ( people > dogs )
{
System.out.println( "The world is dry!" );
}
dogs += 5;
if (people >= dogs )
{
System.out.println( "People are greater than or equal to dogs." );
}
if ( people <= dogs )
{
System.out.println( "people are less than or equal to dogs." );
}
if ( people == dogs )
{
System.out.println( "People are dogs." );
}
}
}
/// I believe that when an If is inserted into the code, it activates as a Boolean expression in the sense if a statement is true, it is displayed, while if it any way its false nothing is displayed.
/// The curly brackets create a region where statements can be created that only affect one specific if statement.
Picture of the output