MapleStory Finger Point

๐Ÿƒ‍โ™€๏ธprogrammers/Java

ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค - java ๊ฐ„๋‹จํ•œ ์‹ ๊ณ„์‚ฐํ•˜๊ธฐ

HYEJU01 2024. 5. 8. 10:33

 

๐Ÿ’ก ๊ฐ๊ฐ ๊ณต๋ฐฑ์„ ๊ธฐ์ค€์œผ๋กœ ์ž˜๋ผ์ฃผ๊ณ 

๊ทธ ๊ฐ’๋“ค์„ ํ˜•๋ณ€ํ™˜ ์‹œ์ผœ์ค€ ๋’ค 

switch ๋ฌธ์— ๋„ฃ์–ด ์ฒ˜๋ฆฌํ•ด์ค€๋‹ค.

 

 

 ๐Ÿ’ฌ Integer.parseInt() :: ๋ฌธ์ž์—ด  --->  ์ •์ˆ˜ int ๋กœ ๋ณ€ํ™˜

 ๐Ÿ’ฌ str[1].charAt(0) :: ๋ฌธ์ž์—ด๋ฐฐ์—ด  --- >  char ๋กœ ๋ณ€ํ™˜ํ•  ๋•Œ

 

class Solution {
    public int solution(String binomial) {
        int answer = 0;
        
        String[] str = binomial.split(" ");
        
        int a = Integer.parseInt(str[0]); int b = Integer.parseInt(str[2]);
        
        char op = str[1].charAt(0); //๋ฐฐ์—ด์—์„œ ์›ํ•˜๋Š” ๋ฌธ์ž์—ด์„ ์„ ํƒํ•œ ๋‹ค์Œ์— ํ•ด๋‹น ๋ฌธ์ž์—ด์—์„œ ๋ฌธ์ž๋ฅผ ์ถ”์ถœ
        
        switch (op){
            case '+':
                answer = a + b;
                break;
            case '-':
                answer = a - b;
                break;
            case '*':
                answer = a * b;
                break;
        }
        
        return answer;
    }
}