
public class MathFun {

	public static void main(String[] args) {
		System.out.println(Math.PI);
		
		double sqrt2 = Math.sqrt(2);
		
		System.out.println(sqrt2);
		
		double two = sqrt2*sqrt2;
		
		//avoid comparing doubles with ==
		if(two == 2.0) {
			System.out.println("They are equal.");
		}
		else {
			System.out.println("They are not equal?");
		}
		System.out.println(two);
		
		double sqrt4 = Math.sqrt(4);
		System.out.println(sqrt4);
		System.out.println(sqrt4*sqrt4);
		
		//close enough?
		double close = 0.0000001;
		
		//Is two close enough to 2.0
		if (Math.abs(two-2.0) < close) {
			System.out.println("Close enough");
		}
		else {
			System.out.println("Not close enough");
		}
		
		System.out.println("Hello there");
		System.out.print("Hello there\n");
		
		//printf - formatted printing
		System.out.printf("Hello there\n");
		
		int n = 10;
		int m = 20;
		
		System.out.println("n equals " + n + ".");
		
		//printf - fill in the blanks
		// format string
		//  %d - integer
		System.out.printf("n equals %d.\n", n);
		
		System.out.printf("n equals %d. m equals %d.\n", n, m);
		
		//print out n and m as an ordered pair
		System.out.printf("( %d, %d)\n", n, m);
		
		// %f - floating point (double)
		// %.3f - 3 digits after the decimal point
		System.out.printf("The square root of two is %.3f.\n", sqrt2);
		
		//4th digit of pi is rounded 
		System.out.printf("pi =%.4f.\n", Math.PI);
	}
}
