Math.ceil - 올림
문법
Math.ceil( double a)
예제
System.out.println( Math.ceil(10.3));
// 11.0 출력
System.out.println( Math.ceil(10.5));
// 11.0 출력
System.out.println( Math.ceil(10.6));
// 11.0 출력
Math.floor - 내림
문법
Math.floor( double a)
예제
System.out.println( Math.floor(10.3));
// 10.0 출력
System.out.println( Math.floor(10.5));
// 10.0 출력
System.out.println( Math.floor(10.6));
// 10.0 출력
Math.floor - 내림
문법
Math.round( double a)
예제
System.out.println( Math.round( 10.3));
// 10 출력
System.out.println( Math.round( 10.5));
// 11 출력
System.out.println( Math.round( 10.6));
// 11 출력
Math.pow - 지수
문법
Math.pow( double a, double b)
예제
System.out.println(Math.pow(10.0, 2.0));
// 100.0 출력
System.out.println(Math.pow(10, 2));
// 100.0 출력
System.out.println(Math.pow(10.0, 3.0));
// 1000.0 출력
Math.random - 난수
문법
Math.random(), 난수 범위: 0 <= x < 1 실수
예제
System.out.println( Math.random());
// 0 <= x < 1 실수
System.out.println((int)(Math.random() * 10));
// 0 <= x < 10인 정수((int)를 통한 강제 형변환)
System.out.println( (int)(((Math.random() * 45) + 1 )) );
// 1 <= x < 46인 정수
Math.max - 최댓값
문법
Math.max(double a, double b)
예제
System.out.println( Math.max(10.0, 20.0));
// 20.0 출력
Math.min - 최솟값
문법
Math.min(double a, double b)
예제
System.out.println( Math.min(10.0, 20.0));
// 10.0 출력
'Java' 카테고리의 다른 글
[Java] Wrapper 클래스 / Integer 클래스 / intValue() 메서드 / valueOf() 메서드 / parseInt() 메서드 (0) | 2022.10.03 |
---|---|
[Java] String / StringBuffer / StringBuilder (0) | 2022.10.03 |
[Java] Obect 클래스 / toString() / equals() / hashCode() (0) | 2022.10.03 |
[Java] final 예약어 (0) | 2022.10.01 |
[Java] 주민등록번호 유효성 검사 메서드 / 재활용성을 고려한 (0) | 2022.09.30 |