The math2 class Class Invariants All methods data must be
The math2 class
Class Invariants
• All methods & data must be static.
Data Items
• Define a static constant (use final) for the mathematical constant pi.
• Define a second constant for E. o Should we make this data private? public?
• Note that we avoid calling this section Data Members, as these are not instance variables but rather static, shared data.
Methods
• public int max(int a, int b);
• public double max(double a, double b);
• public int pow(int base, int exp);
Sample Output
The larger of the two is 20.0
And the larger of the two is 10.34
2^8 is 256
-------------Driver-------------
double a = Math2.PI;
double b = Math2.E;
double c = a + b;
System.out.println(\" The larger of the two is \" + Math2.max(10,20));
System.out.println(\" And the larger of the two is \" +
Math2.max(10.34,10.31));
System.out.println(\"2^8 is \" + Math2.pow(2,8) );
Solution
Please find the required program along with its output. Please see the comments against each line to understand the step.
-----------------------
OUTPUT:
The larger of the two is 20
And the larger of the two is 10.34
2^8 is 256
