class Solution {
public int solution(String my_string) {
// 공백을 기준으로 문자열을 분리하여 숫자와 연산자를 배열에 저장
String[] nums = my_string.split(" ");
// 초기값으로 첫 번째 숫자를 저장
int result = Integer.parseInt(nums[0]);
// 연산자와 숫자를 번갈아가며 계산
for (int i = 1; i < nums.length; i += 2) {
// "+" 연산자일 경우, 현재 숫자를 더함
if (nums[i].equals("+")) {
result += Integer.parseInt(nums[i+1]);
// "-" 연산자일 경우, 현재 숫자를 뺌
} else if (nums[i].equals("-")) {
result -= Integer.parseInt(nums[i+1]);
}
}
return result;
}
}