Notice
Recent Posts
Recent Comments
Link
«   2024/07   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31
Tags
more
Archives
Today
Total
관리 메뉴

WON.dev

chapter08 : Big_number 본문

JAVA/chapter20_api

chapter08 : Big_number

GAWON 2023. 5. 30. 18:23
package org.joonzis.ex;

import java.math.BigDecimal;
import java.math.BigInteger;

public class Ex08_Big_number {
	public static void main(String[] args) {
		
		// int형 최대 값
		System.out.println(Integer.MAX_VALUE);
		// long형 최대 값
		System.out.println(Long.MAX_VALUE);
		
		
		// BigInteger 클래스를 활용해서 long 타입 이상/이하 사용 가능
		// 반드시 문자열 처리해서 적어주자
		BigInteger a = new BigInteger("12345678901234567890");
		BigInteger b = new BigInteger("123456789012345678901234567890");
		
		// BigInteger 필드 값
		System.out.println(BigInteger.ZERO);
		System.out.println(BigInteger.ONE);
		System.out.println(BigInteger.TEN);
		
		// 사칙연산
		System.out.println(a.add(b));
		System.out.println(a.subtract(b));
		System.out.println(a.multiply(b));
		System.out.println(a.divide(b));
		
		// BigDecimal 클래스로 실수의 소수 자릿수를 제한없이 사용 가능
		double d = 1.23456789123456789;
		System.out.println(d);
		BigDecimal e = new BigDecimal("1.123456789123456789123456789");
		System.out.println(e);
		
	
	}
}

'JAVA > chapter20_api' 카테고리의 다른 글

chapter10 : Date_SimpleDateFormat  (0) 2023.05.30
chapter09 : Calendar  (0) 2023.05.30
chapter07 : Wrapper  (0) 2023.05.30
chapter06 : StringBuffer  (0) 2023.05.30
chapter05 : String  (0) 2023.05.30