Notice
Recent Posts
Recent Comments
Link
250x250
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 31 |
Tags
- java
- SQLP
- 코딩테스트
- 프로그래머스
- 챗지피티
- 탐욕알고리즘
- ChatGPT
- JQuery
- 그리디알고리즘
- 개발자
- API
- 자바
- 개발
- Spring
- 네트워크
- 알고리즘
- 파이썬
- codingtest
- 알고리즘코딩테스트
- 하루코딩
- SQL
- 정렬알고리즘
- Python
- HTTP
- jsp
- 서버
- 백준
- javascript
- SQLD
- HTTP상태
Archives
- Today
- Total
개발자's Life
[Coding Test] 백준 - 11382번 꼬마 정민 본문
728x90
반응형
문제
꼬마 정민이는 이제 A + B 정도는 쉽게 계산할 수 있다. 이제 A + B + C를 계산할 차례이다!
입력
첫 번째 줄에 A, B, C (1 ≤ A, B, C ≤ 1012)이 공백을 사이에 두고 주어진다.
출력
A+B+C의 값을 출력한다.
우선 내 처음 코드는 NumberFormat 에러 발생하였다..
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String temp = in.nextLine();
int result = 0;
if(temp.split(" ").length > 2){
String[] temp_list = temp.split(" ");
for(int i = 0; i < temp_list.length; i++){
result += Integer.parseInt(temp_list[i]);
};
}else{
result = Integer.parseInt(temp);
}
System.out.println(result);
}
}
공백을 두고 한번에 입력이 되는 줄 알고 " " 공백을 split 하여 각 더해주니 NumberFormat 에러 발생하였다..
뭐가 잘 못 됬는지 찾다가 설마..? 하고 했더니 해결이 되었다.
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
Long a = in.nextLong();
Long b = in.nextLong();
Long c = in.nextLong();
System.out.println(a+b+c);
}
}
각 하나씩 입력 받는 문제였다.
Long 타입으로 받아서 더해주었다.
728x90
'코딩테스트' 카테고리의 다른 글
[Coding Test] 백준(반복문) - 영수증 (0) | 2023.03.11 |
---|---|
[Coding Test] 백준 - 주사위 세계 (0) | 2023.03.11 |
[Coding Test] 백준 - 18108번 1998년생인 내가 태국에서는 2541년생? (0) | 2023.03.07 |
[프로그래머스] java 스킬 체크 테스트 Level.2 Split 함수 사용 (0) | 2022.08.20 |
[프로그래머스] 스킬 체크 테스트 Level.1 (0) | 2022.08.19 |
Comments