Assignemnt 11 and Numbers And Math
Code
/// Name: Xinting Chen
/// Period: 5
/// Program Name:Numbers And Math
/// File Name: NumbersAndMath.java
/// Date Finished: 9/11/2015
public class NumbersAndMath
{
public static void main( String[] args )
{
System.out.println( "I will now count my chickens:" );
//It will have output of the sentence.
System.out.println( "Hens " + ( 25.0 + 30.0 / 6.0 ) );
//This line calulates how many hens are there by dividing 30 by and add 25, which gets the result of 30.
System.out.println( "Roosters " + ( 100.0 - 25.0 * 3.0 % 4.0 ) );
//This line uses 25 times 3 modulus times 4 to subtract from 100 and gets 97.
System.out.println( "Now I will count the eggs:" );
//Output the sentence.
System.out.println( 3.0 + 2.0 + 1.0 - 5.0 + 4.0 % 2.0 - 1.0 / 4.0 + 6.0 );
//This line add 3 and 2 and 1 and 6 and 4 modulus times 2, then subtract 5 and 1/4, and gets the result of 7.
System.out.println( "Is it true that 3.0 + 2.0 < 5.0 - 7.0?" );
//here, the numbers did not add together since those numbers are in the quotation.
System.out.println( 3 + 2 < 5 - 7 );
//In this line, the computer automatically determined that this is a false inequality.
System.out.println( "What is 3.0 + 2.0? " + ( 3.0 + 2.0 ) );
//The numbers in the () were calulated by the computer, numbers in the "" did not.
System.out.println( "What is 5.0 - 7.0? " + ( 5.0 - 7.0 ) );
//In the quotation marks, 5 minus 7 is not calculated, whereas in (), 5 minus 7 is calculated.
System.out.println( "Oh, that's why it's false." );
//Output the sentence.
System.out.println( "How about some more." );
//Output the sentence.
System.out.println( "Is it greater? " + ( 5.0 > -2.0 ) );
//In this line, the inequalty 5 is greater than -2, and this program automatically determined that the inequality is true.
System.out.println( "Is it greater or equal? " + ( 5.0 >= -2.0 ) );
//Same as last sentence.
System.out.println( "Is it less or equal? " + ( 5.0 <= -2.0 ) );
//In this case, the inequality is false.
}
}
Picture of the output