[백준 10952] A+B - 5 / Java

Hyeongmin Jung·2022년 11월 19일
0

java

목록 보기
3/28

링크 | https://www.acmicpc.net/problem/10952

문제 |

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

입력 |

입력은 여러 개의 테스트 케이스로 이루어져 있다.
각 테스트 케이스는 한 줄로 이루어져 있으며, 각 줄에 A와 B가 주어진다. (0 < A, B < 10)
입력의 마지막에는 0 두 개가 들어온다.

출력 |

각 테스트 케이스마다 A+B를 출력한다.

예제 |

입력

1   1
2   3
3   4
9   8
5   2
0   0

출력

2
5
7
17
7

Solution |

import java.util.Scanner;

public class AplusB_5 {
	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int a, b;
		int[] ans = new int[1000];
		int i=0; 
		
		while(true) {
			a = input.nextInt();
			b = input.nextInt();
			
			if (a==0 && a==0) {
				print(ans, i);
                input.close();
				return;
			}
			
			ans[i] = a+b;
			i++;
		}
	}

    static void print(int[] arr, int r) {
        for (int i = 0; i < r; i++)
            System.out.println(arr[i]);
    }
}

0개의 댓글