728x90
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int x = scanner.nextInt();
int y = scanner.nextInt();
int x1 = x/y;
int y1 = x%y;
System.out.println(x1);
System.out.println(y1);
scanner.close();
}
}
๋ฌธ์ ๋ฅผ ๋ณด๊ณ ์ ์ถ์ ํ๋๋ฐ, ๊ณ์ ๋ฐํ์ ์๋ฌ๊ฐ ๋ฌ๋ค. ๋ถ๋ช ํ๋ฆด๋ฆฌ๊ฐ ์๋ค๊ณ ์๊ฐํ๊ธฐ ๋๋ฌธ์, ๋ฌธ์ ๋ฅผ ๋ค์ ์ดํด๋ณด์๋ค.
๋ฌธ์ ๋ฅผ ํ์ธํ๋ ์์ฃผ ํฐ ์ซ์๋ฅผ ๋ฃ์ด์ผํ๋ค๋ ๊ฒ์ด์๋ค. int, long ๋ณด๋ค ํฐ ์๋ฅผ ๋ฃ์ ์ ์์ด์ผ ํ๊ธฐ ๋๋ฌธ์ ๋ค๋ฅธ ๋ฐ์ดํฐ ์ ์ฅ์๊ฐ ํ์ํ๋ ๊ฒ์ด๋ค.
import java.math.BigInteger;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
BigInteger x = scanner.nextBigInteger();
BigInteger y = scanner.nextBigInteger();
scanner.close();
System.out.println(x.divide(y));
System.out.println(x.remainder(y));
}
}
math ํจํค์ง ๋ด์ ์๋ BigInteger๋ฅผ ์ฌ์ฉํ์ฌ ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ์๋ค.
- divide : ๋๋๊ธฐ
- remainder : ๋๋จธ์ง
728x90
'PS > BaekJoon' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
3052 JAVA ๋๋จธ์ง (0) | 2022.06.30 |
---|---|
2439 JAVA ๋ณ์ฐ๊ธฐ -2 (0) | 2022.06.22 |
10699 JAVA ์ค๋ ๋ ์ง (0) | 2022.06.20 |
2420 JAVA ์ฌํ๋ฆฌ์๋ (0) | 2022.06.20 |
10872 JAVA ํฉํ ๋ฆฌ์ผ ์๊ณ ๋ฆฌ์ฆ (0) | 2022.06.20 |