This is basic syntax of math class. Various type of example using Math class. 

Source Code:
  1. public class MathDemo {
  2. public static void main(String[] args) {
  3. // TODO Auto-generated method stub
  4. int a = 10,max;
  5. int b = 20;
  6. int c = -15;
  7. double x = 2,y = 3;
  8. float z = 8.49f;
  9. max = Math.max(a, b);
  10. System.out.printf("max is-%d",max); //Showing maximum value.
  11. System.out.println("\nmin is -"+Math.min(a, b)); //Showing minimum value.
  12. System.out.printf("Absolute value is-%d ",Math.abs(c));    //Showing absolute value.
  13. System.out.println("\n X to the power of Y-: "+Math.pow(x, y));
  14. System.out.println("round no. id-"+Math.round(z));
  15. System.out.println("pi = "+Math.PI);
  16. }
  17. }

Output:

max is-20
min is -10
Absolute value is-15 
 X to the power of Y-: 8.0
round no. id-8
pi = 3.141592653589793

0 comments:

Post a Comment