/* CalcFormatDemo.java
   Craig Persiko
   CS 111A Sample Program demonstrating behavior of calculations and printf formatting
   with floating point and integer variables.
*/

import java.util.Scanner;


public class CalcFormatDemo
{
  public static void main(String[] args)
  {
    Scanner consoleIn = new Scanner(System.in);
    int i1, i2;
    double d1, d2;

    System.out.print("Please enter two integers, separated by a space: ");
    i1 = consoleIn.nextInt();
    i2 = consoleIn.nextInt();

    System.out.println(i1 + " * " + i2 + " = " + i1 * i2);
    System.out.println(i1 + " / " + i2 + " = " + i1 / i2);
    System.out.println(i1 + " % " + i2 + " = " + i1 % i2);

    System.out.print("Please enter two floating-point numbers, separated by a space: ");
    d1 = consoleIn.nextDouble();
    d2 = consoleIn.nextDouble();

    System.out.println(d1 + " * " + d2 + " = " + d1 * d2);
    System.out.println(d1 + " / " + d2 + " = " + d1 / d2);
    System.out.println(d1 + " % " + i2 + " = " + d1 % i2);

    System.out.println("Formatting those same calculations to show commas for thousands,");
    System.out.println("and just 1 digit after the decimal point gives us:");
    System.out.printf("%,.1f * %,.1f = %,.1f \n", d1, d2, d1 * d2);
    System.out.printf("%,.1f / %,.1f = %,.1f \n", d1, d2, d1 / d2);
    System.out.printf("%,.1f %% %,d = %,.1f \n", d1, i2, d1 % i2);
    
    System.out.printf("For a simpler example, The first integer you entered was %,d "
		      + "(displayed with commas for thousands)\n", i1);

  }
}

/*
Sample Output:

[cpersiko@fog cs111a]$ javac CalcFormatDemo.java
[cpersiko@fog cs111a]$ java CalcFormatDemo
Please enter two integers, separated by a space: 1000 5
1000 * 5 = 5000
1000 / 5 = 200
1000 % 5 = 0
Please enter two floating-point numbers, separated by a space: 2.5 5.2
2.5 * 5.2 = 13.0
2.5 / 5.2 = 0.4807692307692307
2.5 % 5 = 2.5
Formatting those same calculations to show commas for thousands,
and just 1 digit after the decimal point gives us:
2.5 * 5.2 = 13.0 
2.5 / 5.2 = 0.5 
2.5 % 5 = 2.5 
For a simpler example, The first integer you entered was 1,000 (displayed with commas for thousands)
[cpersiko@fog cs111a]$ java CalcFormatDemo
Please enter two integers, separated by a space: 2000 1500
2000 * 1500 = 3000000
2000 / 1500 = 1
2000 % 1500 = 500
Please enter two floating-point numbers, separated by a space: 123.456 0.789
123.456 * 0.789 = 97.406784
123.456 / 0.789 = 156.47148288973384
123.456 % 1500 = 123.456
Formatting those same calculations to show commas for thousands,
and just 1 digit after the decimal point gives us:
123.5 * 0.8 = 97.4 
123.5 / 0.8 = 156.5 
123.5 % 1,500 = 123.5 
For a simpler example, The first integer you entered was 2,000 (displayed with commas for thousands)
[cpersiko@fog cs111a]$ 


*/


syntax highlighted by Code2HTML, v. 0.9