반응형
*자바 큰 수 사칙연산 (BigInteger)
1. 큰 수의 덧셈 ( add )
import java.util.Scanner;
import java.math.BigInteger;
class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
BigInteger num1 = scanner.nextBigInteger();
BigInteger num2 = scanner.nextBigInteger();
scanner.close();
BigInteger temp = num1.add(num2);
System.out.println(temp);
}
}
2. 큰 수의 뺄셈 ( subtract )
import java.util.Scanner;
import java.math.BigInteger;
class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
BigInteger num1 = scanner.nextBigInteger();
BigInteger num2 = scanner.nextBigInteger();
scanner.close();
BigInteger temp = num1.subtract(num2);
System.out.println(temp);
}
}
3. 큰 수의 곱셈 ( multiply )
import java.util.Scanner;
import java.math.BigInteger;
class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
BigInteger num1 = scanner.nextBigInteger();
BigInteger num2 = scanner.nextBigInteger();
scanner.close();
BigInteger temp = num1.multiply(num2);
System.out.println(temp);
}
}
4. 큰 수의 나눗셈 ( divide )
import java.util.Scanner;
import java.math.BigInteger;
class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
BigInteger num1 = scanner.nextBigInteger();
BigInteger num2 = scanner.nextBigInteger();
scanner.close();
BigInteger temp = num1.divide(num2);
System.out.println(temp);
}
}
반응형
'기타' 카테고리의 다른 글
인력관리소(링크드 리스트 이용) (0) | 2020.04.29 |
---|---|
자바 인력관리소 (0) | 2020.04.28 |
이클립스 사용방법 (0) | 2020.04.27 |
거품 정렬(Bubble sort)이란? (0) | 2020.04.24 |
지역 변수와 인스턴스 변수란? (0) | 2020.04.24 |