본문 바로가기

Java/Method

Math Class Method

 

Method 

Comment 

 static double abs(double a)
 static float abs(float f)
 static int abs(int f)
 static long abs(long f)

 주어진 값의 절대값을 반환한다.

 static double ceil(double a)

 주어진 값을 올림하여 반환한다.

 static double floor(double a)

 주어진 값을 버림하여 반환한다.

 static double max(double a, double b)
 static float max(float a, float b)
 static int max(int a, int b)
 static long max(long a, long b)

 주어진 값을 비교하여 큰 쪽을 반환한다.

 static double min(double a, double b)
 static float min(float a, float b)
 static int min(int a, int b)
 static long min(long a, long b)

 주어진 값을 비교하여 작은 쪽을 반환한다.

 static double random()

 0.0~1.0 범위의 임의의 double 값을 반환한다.
 0.0은 범위에 포함되지만 1.0은 포함되지 않는다

 static double rint(double a)

 주어진 double 값과 가장 가까운 정수 값을 double 형으로 반환한다.

 static long round(double a)
 static long round(float a)

 소수점 첫째자리에서 반올림한 정수값(long)을 반환한다.

Example

 Code

 Result

 int i = Math.abs(-10);
 double d = Math.abs(-10.0);
 i=10
 d=10.0
 double d1 = Math.ceil(10.1);
 double d2 = Math.ceil(-10.1);
 double d3 = Math.ceil(10.0000015);
 d1 = 11.0
 d2 = -10.0
 d3 = 11.0
 double d1 = Math.flor(10.8);
 double d2 = Math.flor(-10.8);
 d1 = 10.0
 d2 = -11.0
 double d = Math.max(9.5,9.50001);
 int i = Math.max(0, -1);
 d = 9.50001
 i = 0

 double d = Math.min(9.5,9.50001);

 int i = Math.min(0, -1);

 d = 9.5
 i = -1

 double d = Math.random();
 int i = (int)(Math.random()*10)+1
 d = 0.0~1.0의 실수
 i = 1~10의 정수
 double d1 = Maht.rint(5.55);
 double d2 = Maht.rint(5.11);
 double d3 = Maht.rint(-5.55);
 double d4 = Maht.rint(-5.11);
 d1 = 6.0
 d2 = 5.0
 d3 = -6.0
 d4 = -5.0
 long l1 = Math.round(5.55);
 long l2 = Math.round(5.11);
 long l3 = Math.round(-5.55);
 long l4 = Math.round(-5.11);
 double d1 =90.7552;
 double d2 = Math.round(d*100)/100.0;
 l1 = 6
 l2 = 5
 l3 = -6
 l4 = -5
 d1 = 90.7552
 d2 = 90.76

 


'Java > Method' 카테고리의 다른 글

Map Interface  (0) 2015.08.19
List Interface  (0) 2015.08.19
Collection Interface  (0) 2015.08.19
StringBuffer Method  (0) 2015.08.19
String Class Constructor & Method  (0) 2015.08.19