# Table of Contents

# Math

Math클래스는 수학 연산을 위한 다양한 메소드를 제공한다.

import java.lang.Math;

# abs()

절대값을 반환한다.

int result1 = Math.abs(-10);  // 10
int result2 = Math.abs(10);  // 10
double result3 = Math.abs(-10.3);  // 10.3

# random()

0 보다 크거나 같고, 1보단 작은 dobule형 숫자를 반환한다.

double random = Math.random();

다음과 같이 정수형 난수를 생성할 수 있다.

(int)(Math.random() * 10);      // 0 ~ 9 사이 난수 발생
(int)(Math.random() * 100);     // 0 ~ 99 사이 난수 발생   
(int)(Math.random() * 1000);    // 0 ~ 999 사이 난수 발생   

# floor()

소수점 이하를 내림한다.

double result1 = Math.floor(1.4);    // 1.0
double result2 = Math.floor(1.5);    // 1.0

# ceil()

소수점 이하를 올림한다.

double result1 = Math.ceil(1.4);    // 2.0
double result2 = Math.ceil(1.5);    // 2.0

# round()

소수점 이하를 반올림한다.

double result1 = Math.round(1.4);    // 1.0
double result2 = Math.round(1.5);    // 2.0

다음과 같은 방법으로 소수점을 절사할 수 있다.

double pie = 3.1494949498;

Math.round(pie*10)/10.0;   // 3.1
Math.round(pie*100)/100.0;   // 3.15
Math.round(pie*1000)/1000.0;   // 3.149
Math.round(pie*10000)/10000.0;   // 3.1495

# max()

두 인자 중 큰 숫자를 반환한다.

Math.max(10, 40);   // 40

# min()

두 인자 중 작은 숫자를 반환한다.

Math.min(10, 40);   // 10

# pow()

Power, 거듭 제곱을 반환한다.

Math.pow(5, 2);     // 25 

# sqrt()

Square, 제곱근을 반환한다.

Math.sqrt(25);      // 5