๋ฐ์ํ
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
public class Main {
// 15552 ๋น ๋ฅธ A+B
public static void main(String[] args) throws IOException {
BufferedReader bfr = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bfw = new BufferedWriter(new OutputStreamWriter(System.out));
int t = Integer.parseInt(bfr.readLine());
for (int i=0; i<t; i++) {
String input = bfr.readLine();
String[] inputArr = input.split(" ");
int sum = Integer.parseInt(inputArr[0]) + Integer.parseInt(inputArr[1]);
bfw.write(sum + "\n");
}
bfw.flush();
bfw.close();
}
}
BufferedReader์ BufferedWriter class๋ ๋จผ์ ๋งํ์๋ฉด Scanner class ์ด์ ์ ์ฐ์ด๋ class๋ก
Scanner ๋ณด๋ค ๋น ๋ฅด์ง๋ง ์ ๊ท์ ๋ณํ์ด ์๋๋ ๋ฑ์ ๋จ์ ์ด ์์ต๋๋ค.
- ๋ฌธ์ ์์ฒด๊ฐ BufferedReader์ BufferedWriter class๋ฅผ ์ฌ์ฉํด์ผ ํฉ๋๋ค.
- ๋ class ๋ค String๋ง ๋ค๋ฃฐ ์ ์๊ธฐ ๋๋ฌธ์ ํ๋ณํ์ด ํ์์ ๋๋ค.
- try & catch ๋๋ IOException ์ฒ๋ฆฌ ํ์(๋ณดํต IOXception ์ฌ์ฉ)
thorws IOException ( Input & Output Exception ) ์ ์ถ๋ ฅ์์ธ์ฒ๋ฆฌ
https://learn.microsoft.com/ko-kr/dotnet/api/system.io.ioexception?view=net-7.0
๋ฐ์ํ
'๐ธ Algorithm > ๐ธ ๋ฐฑ์ค BaekJoon' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[๋ฐฑ์ค][java][11022][A+B - 8] (1) | 2023.10.08 |
---|---|
[๋ฐฑ์ค][java][11021][A+B - 7] (0) | 2023.10.08 |
[๋ฐฑ์ค][java][25314][์ฝ๋ฉ์ ์ฒด์ก๊ณผ๋ชฉ ์ ๋๋ค] (0) | 2023.10.03 |
[๋ฐฑ์ค][java][25304][์์์ฆ] (0) | 2023.10.03 |
[๋ฐฑ์ค][java][8393][ํฉ] (0) | 2023.10.03 |