๐Ÿ•ธ Algorithm/๐Ÿ•ธ ๋ฐฑ์ค€ BaekJoon

[๋ฐฑ์ค€][java][15552][๋น ๋ฅธ A+B]

๋‰ด์ด NUEY 2023. 10. 8. 20:41
๋ฐ˜์‘ํ˜•

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

 

 

 

 

๋ฐ˜์‘ํ˜•