본문 바로가기
JAVA

221018 Math

Math
Math클래스는 수학 계산에 사용할 수 있는 메서드들을 제공
모두 정적(static)메서드임.

예시
abs() :절대값
celi() :올림값
floor() :내림값
max() :최대값
min() :최소값
random() :랜덤값
rint() :현재수에서 가까운 정수를 실수형태로
round() :반올림값

 

package api.lang.math;

public class MathEx {
	public static void main(String[] args) {
		
		//올림
		double d=Math.ceil(1.3);
		System.out.println(d);
		
		//내림
		double d2 = Math.floor(1.2);
		System.out.println(d2);
		
		//반올림
		double d3=Math.round(3.14);
		System.out.println(d3);
		
		//루트값
		double d4=Math.sqrt(16);
		System.out.println(d4);
		
		//절대값
		double d5=Math.abs(-4);
		System.out.println(d5);
		
		//대소비교
		int i1=Math.max(5, 3);
		System.out.println(i1);
		
		int i2 = Math.min(5, 3);
		System.out.println(i2);
		
		//현재상태에서 가장 가까운 정수를 실수형태로
		System.out.println(Math.rint(-7.21));
		
		
	}

}
2.0
1.0
3.0
4.0
4.0
5
3
-7.0

static이라 객체 생성 안함.

예시들을 확인하고, 실제로 사용할 때도 모르면 이클립스 설명 참조 or 구글링

'JAVA' 카테고리의 다른 글

221024 WrapperClass 보충  (0) 2022.10.24
221018 Wrapper클래스-Boxing, UnBoxing, AutoBoxing  (0) 2022.10.18
221018 StringBuilder  (0) 2022.10.18
221018 API String 실습  (0) 2022.10.18
221018 API System, String  (0) 2022.10.18