본문 바로가기
JAVA

Test134.java / 자바의 주요(중요) 클래스 / math 클래스

by universedevelope 2022. 10. 23.
/* ===================================================
      ■ ■ ■  자바의 주요(중요) 클래스 ■ ■ ■
====================================================*/

// math 클래스

import java.math.BigInteger;


public class Test134
{
	public static void main(String[] args)
	{
		BigInteger a = new BigInteger("123456789123456789");
		BigInteger b = new BigInteger("123456789123456789");
		
		//BigInteger c = a + b;
		//System.out.println(c);	-- 오류

		// 더하기
		BigInteger c = a.add(b);
		System.out.println("덧셈 결과 : " + c);
		// 덧셈 결과 : 246913578246913578

		BigInteger d = a.subtract(b);
		System.out.println("뺄셈 결과 : " + d);
		//뺄셈 결과 : 0

		BigInteger e = a.multiply(b);
		System.out.println("곱셈 결과 : " + e);
		// 곱셈 결과 : 15241578780673678515622620750190521

		BigInteger f = a.divide(b);
		System.out.println("나눗셈 결과 : " + f);
		//나눗셈 결과 : 1
		
		BigInteger g = new BigInteger("2");
		System.out.println("2의 3승 : " + g.pow(3));
	


	}
}

/*
덧셈 결과 : 246913578246913578
뺄셈 결과 : 0
곱셈 결과 : 15241578780673678515622620750190521
나눗셈 결과 : 1
2의 3승 : 8
*/
728x90

댓글