https://school.programmers.co.kr/learn/courses/30/lessons/120902
TISTORY
나를 표현하는 블로그를 만들어보세요.
www.tistory.com
class Solution {
private static final char PLUS = '+';
private static final char MINUS = '-';
public int solution(String my_string) {
int answer = 0;
String[] temp = my_string.split(" ");
answer = Integer.parseInt(temp[0]);
for(int i = 1 ; i < temp.length ; i += 2){
int num = Integer.parseInt(temp[i+1]);
char oper = temp[i].charAt(0);
if(oper == PLUS){
answer += num;
}else{
answer -= num;
}
}
return answer;
}
}
'알고리즘' 카테고리의 다른 글
프로그래머스 과일 장수 (JAVA) (0) | 2023.01.05 |
---|---|
프로그래머스 문자열 정렬하기 (JAVA) (0) | 2023.01.04 |
프로그래머스 각도기 (JAVA) (0) | 2023.01.02 |
프로그래머스 대문자와 소문자 (JAVA) (0) | 2023.01.01 |
프로그래머스 피자 나눠 먹기 (JAVA) (0) | 2022.12.31 |