|
public class Mathdemo {
public static void Main (string[] args) {
public static final Double PI
System.out.println ("PI:" + Math.PI);
public static final Double E
System.out.println ("E:" + MATH.E);
System.out.println ("--------------");
public static int abs (int a): absolute Value
System.out.println ("ABS:" + Math.Abs (10));
System.out.println ("ABS:" + math.abs (-10));
System.out.println ("--------------");
public static double Ceil (double A): Rounding up
System.out.println ("Ceil:" + Math.ceil (12.34));
System.out.println ("Ceil:" + Math.ceil (12.56));
System.out.println ("--------------");
public static double floor (double A): Rounding down
System.out.println ("Floor:" + Math.floor (12.34));
System.out.println ("Floor:" + Math.floor (12.56));
System.out.println ("--------------");
public static int max (int a,int b): Maximum Value
System.out.println ("Max:" + Math.max (12, 23));
requirement: I want to get the maximum value in three data
nested calls to methods
System.out.println ("Max:" + Math.max (Math.max (12, 23), 18));
requirement: I want to get the maximum value in four data
System.out.println ("Max:"
+ Math.max (Math.max (), Math.max (34, 56));
System.out.println ("--------------");
public static Double pow (double a,double b): Power of b of a
System.out.println ("POW:" + Math.pow (2, 3));
System.out.println ("--------------");
public static Double Random (): random number [0.0,1.0]
System.out.println ("Random:" + math.random ());
get a random number between 1-100
System.out.println ("Random:" + ((int) (Math.random () * 100) + 1));
System.out.println ("--------------");
public static int round (float a) rounded ( self-study with double argument )
System.out.println ("Round:" + math.round (12.34f));
System.out.println ("Round:" + math.round (12.56f));
System.out.println ("--------------");
public static double sqrt (double A): positive square root
System.out.println ("sqrt:" +math.sqrt (4));
}
}
|