백준_31403번 A+B-C

느린달팽이·2025년 8월 7일

백준 Java

목록 보기
1/14

숫자에 경우 그냥 더하고 빼면된다.
문자열 인식 부분이 중요 포인트!!

문자열로 합치고 Integer형식으로 변환하여 뺄샘전에 숫자로 변환시키는 작업을 해야하는 점을 인식하고 코드를 작성해야한다.

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class bj_31403 {

	public static void main(String[] args) throws IOException {
		
		//a,b,c 숫자 +,- 정석대로
		//a,b,c 문자 +는 문자열붙이기, -는 숫자로 인식 후 뺄샘
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
		
		int A = Integer.parseInt(bf.readLine());
		int B = Integer.parseInt(bf.readLine());
		int C = Integer.parseInt(bf.readLine());
		
		//출력!!!
		//첫줄 숫자 인식 a+b-c
		//둘째 줄 문자인식 a+b-c
		
		//문자열 합치기
		String AB= "";
		AB +=A;
		AB +=B;
		
		//첫번째 숫자 a+b-c출력
		System.out.println(A+B-C);
		//두번째 문자 a+b-c출력 , 문자 -> 숫자로 변경
		System.out.println(Integer.parseInt(AB)-C);
		

	}

}

📎 관련 GitHub 코드 보기
👉 bj_31403.md

profile
한걸음이라도 제대로... 쓰임있는 앱을 만들자

0개의 댓글