๊ด€๋ฆฌ ๋ฉ”๋‰ด

JiYoung Dev ๐Ÿ–ฅ

[JAVA] char ์—์„œ ๋ฌธ์ž์—ด๋กœ ๋ณ€ํ™˜ํ•˜๊ธฐ ๋ณธ๋ฌธ

Question

[JAVA] char ์—์„œ ๋ฌธ์ž์—ด๋กœ ๋ณ€ํ™˜ํ•˜๊ธฐ

Shinjio 2023. 8. 21. 10:45

String.valueOf()

 

    public String solution(String s) {
        String answer = "";

        char[] arr = s.toCharArray();
        
        
        int idx = 0;
        for(int i = 0 ; i < arr.length ; i++) {
        	if(arr[i] != 32) {
        		if(idx % 2 == 0) {
        			answer += String.valueOf(arr[i]).toUpperCase();
        		}
        		else {
        			answer += String.valueOf(arr[i]).toLowerCase();
        		}
        		idx++;
        	}else {
        		idx=0;
        		answer += " ";
        	}
        }
        
        return answer;
    }