어렵지 않앗지만 스캐너에대해서 알게 되는? 문제 였던 것 같다.
문제
이런 문제다
정답
import java.util.Scanner;
public class Main {
public static void main (String[] args) {
Scanner in = new Scanner(System.in);
int A = in.nextInt();
int B = in.nextInt();
int C = in.nextInt();
in.close();
System.out.println( (A+B)%C);
System.out.println(((A%C) + (B%C))%C);
System.out.println( (A*B)%C);
System.out.println( ((A%C) * (B%C))%C);
}
}
처음에 in.close() ;
스캐너를 닫지 않았다.
그랬더니 런타임에러? 이게 발생했다.
스캐너는 System.in 으로 받았으면
메모리가 낭비 될 수 잇어서 닫아주는게 좋다고 한다.
앞으로 닫는 습관은 갖자!

To be continue..
'Codingtest' 카테고리의 다른 글
[코딩테스트] 백준 10171번 고양이 해설집 (0) | 2022.09.25 |
---|---|
[코딩테스트] 백준 2588번 곱셈 해설집 (0) | 2022.09.23 |
[코딩테스트] 백준 3003번 버퍼를 이용한 풀이 (0) | 2022.09.18 |
[코딩테스트] 백준 3003번 킹, 퀸, 룩, 비숍, 나이트, 폰 해설집 (0) | 2022.09.18 |
[코딩테스트] 백준 18108번 1998년생인 내가 태국에서는 2541년생 ?! 해설집 (0) | 2022.09.17 |