백준 코딩테스트 단계별로 풀어보기
3단계 반복문 12단계 10951 A+B -4 문제입니다
https://www.acmicpc.net/problem/10951
10951번: A+B - 4
두 정수 A와 B를 입력받은 다음, A+B를 출력하는 프로그램을 작성하시오.
www.acmicpc.net
단계별로 풀어보기
단계별은 @jh05013님이 관리하고 계십니다. 단계제목설명정보총 문제내가 맞은 문제1입출력과 사칙연산입력, 출력과 사칙연산을 연습해 봅시다. Hello World!132조건문if 등의 조건문을 사용해 봅시다
www.acmicpc.net
문제
두 정수 A와 B를 입력받은 다음, A+B를 출력하는 프로그램을 작성하시오.
입력
입력은 여러 개의 테스트 케이스로 이루어져 있다.
각 테스트 케이스는 한 줄로 이루어져 있으며, 각 줄에 A와 B가 주어진다. (0 < A, B < 10)
출력
각 테스트 케이스마다 A+B를 출력한다.
정답
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNextInt()) {
// hasNextInt()의 사용
// 1) 입력값이 정수일 경우 true를 반환
// 2) 정수가 아닐 경우 예외를 던지며 hasNextInt()에서 false를 반환하면서 더 이상의 입력을 받지 않고 반복문 종료
int A = sc.nextInt();
int B = sc.nextInt();
System.out.println(A+B);
}
}
}
=>
왜 이전 문제보다 더 쉬운 것 같지
이번엔 원하는 조건이 뭐냐?
하면서 일단 기본문으로 때려넣었더니 당연히(?) 틀림
종료값을 0 0 조건으로 준 이전 문제와 달리
더 이상 데이터가 없을 때를 종료 시점으로 주어야 하는 문제
1-1-2557 Hello World https://developernew.tistory.com/41 <- 백준 답지 제출 방법
1-2-1000 A+B https://developernew.tistory.com/42
1-3-1001 A-B https://developernew.tistory.com/43
1-4-10998 AXB https://developernew.tistory.com/44
1-5-1008 A/B https://developernew.tistory.com/45
1-6-10869 사칙연산 https://developernew.tistory.com/46
1-7-10926 ??! https://developernew.tistory.com/47
1-8-18108 1998년생인 내가 태국에서는 2541년생?! https://developernew.tistory.com/48
1-9-10430 나머지 https://developernew.tistory.com/49
1-10-2588 곱셈 https://developernew.tistory.com/50
1-11-11382 꼬마 정민 https://developernew.tistory.com/51
1-12-10171 고양이 https://developernew.tistory.com/52
1-13-10172 개 https://developernew.tistory.com/53
2-1-1330 두 수 비교하기 https://developernew.tistory.com/54
2-2-9498 시험 성적 https://developernew.tistory.com/55
2-3-2753 윤년 https://developernew.tistory.com/56
2-4-14681 사분면 고르기 https://developernew.tistory.com/61
2-5-2884 알람 시계 https://developernew.tistory.com/68
2-6-2525 오븐 시계 https://developernew.tistory.com/69
2-7-2480 주사위 https://developernew.tistory.com/72
3-1-2739 구구단 https://developernew.tistory.com/73
3-2-10950 A+B - 3 https://developernew.tistory.com/75
3-3-8393 합 https://developernew.tistory.com/77
3-4-25304 영수증 https://developernew.tistory.com/79
3-5-25314 코딩은 체육과목 입니다 https://developernew.tistory.com/82
3-6-15552 빠른 A+B https://developernew.tistory.com/83
3-7-11021 A+B -7 https://developernew.tistory.com/85
3-8-11022 A+B -8 https://developernew.tistory.com/86
3-9-2438 별 찍기 -1 https://developernew.tistory.com/87
3-10-2439 별 찍기 -2 https://developernew.tistory.com/89
3-11-10952 A+B -5 https://developernew.tistory.com/90
'코딩테스트 > 백준(JAVA)' 카테고리의 다른 글
백준 코딩테스트 4-2-10871 X보다 작은 수 코딩 문제 java로 푸는 방법 (0) | 2023.03.28 |
---|---|
백준 코딩테스트 4-1-10807 개수 세기 코딩 문제 java로 푸는 방법 (0) | 2023.03.27 |
백준 코딩테스트 3-11-10952 A+B - 5 코딩 문제 java로 푸는 방법 (0) | 2023.03.24 |
백준 코딩테스트 3-10-2439 별 찍기 -2 코딩 문제 java로 푸는 방법 (0) | 2023.03.24 |
백준 코딩테스트 3-9-2438 별 찍기 -1 코딩 문제 java로 푸는 방법 (0) | 2023.03.21 |