Notice
Recent Posts
Recent Comments
«   2024/09   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
Archives
Today
Total
관리 메뉴

충분히 쌓여가는

백준[Java] 10952번 A+B-5 [charAt 사용] 본문

IT/Java[백준]

백준[Java] 10952번 A+B-5 [charAt 사용]

빌드이너프 2023. 2. 22. 10:12

https://www.acmicpc.net/problem/10952

 

10952번: A+B - 5

두 정수 A와 B를 입력받은 다음, A+B를 출력하는 프로그램을 작성하시오.

www.acmicpc.net

문제풀이 1

import java.util.Scanner;
public class _10952_1 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        while (1>0) {
            int A = sc.nextInt();
            int B = sc.nextInt();

            if (A==0 && B==0)
                break;
            else
                System.out.println(A+B);
        }
        sc.close();
    }
}

문제풀이 2

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

public class _10952_2 {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        StringTokenizer st;
        while (1>0) {
            st = new StringTokenizer(br.readLine(), " ");
            int A = Integer.parseInt(st.nextToken());
            int B = Integer.parseInt(st.nextToken());

            if (A==0 && B==0)
                break;
            else
                System.out.println(A+B);
        }
        br.close();
    }
}

문제풀이 3

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

public class _10952_3 {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        StringTokenizer st;
        StringBuilder sb = new StringBuilder();
        while (1>0) {
            st = new StringTokenizer(br.readLine(), " ");
            int A = Integer.parseInt(st.nextToken());
            int B = Integer.parseInt(st.nextToken());

            if (A==0 && B==0)
                break;
            else
                sb.append(A+B).append('\n');
        }
        br.close();
        System.out.println(sb);
    }
}

문제풀이 4

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

public class _10952_4 {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        StringBuilder sb = new StringBuilder();
        while (1>0) {
            String str = br.readLine();
            int A = str.charAt(0)-'0';
            // int A = str.charAt(0) - 48;
            // int A = str.charAt(0) - 48;

            int B = str.charAt(2)-'0';
            // int B = str.charAt(2) - 48;

            if (A==0 && B==0)
                break;
            else
                sb.append(A+B).append('\n');
        }
        br.close();
        System.out.println(sb);
    }
}