[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค] LV.2 ๋ฌธ์ž์—ด ๋งŒ๋“ค๊ธฐ (์ž๋ฐ” java)

 

1. ๋ฌธ์ œ : https://school.programmers.co.kr/learn/courses/30/lessons/12951?language=java 

 

2. ํ’€์ด

๋ฐ˜๋ณต๋ฌธ ๋Œ๋ฉด์„œ ๊ณต๋ฐฑ์„ ๊ธฐ์ค€์œผ๋กœ ๋Œ€๋ฌธ์ž๋กœ ๋ณ€ํ™˜

 

3. ์ฝ”๋“œ

 

class Solution {
    public String solution(String s) {
        String answer = "";
        s = s.toLowerCase();
        for(int i=0;i<s.length();i++){
            char temp = s.charAt(i);
            if(i==0){
                if(Character.isDigit(temp)) answer += temp;
                else answer += Character.toUpperCase(temp);
            }
            else{
                if(s.charAt(i-1) == ' ') answer += Character.toUpperCase(temp);
                else answer += temp;
            }
        }
        return answer;
    }
}

 

 

  • ๋„ค์ด๋ฒ„ ๋ธ”๋Ÿฌ๊ทธ ๊ณต์œ ํ•˜๊ธฐ
  • ๋„ค์ด๋ฒ„ ๋ฐด๋“œ์— ๊ณต์œ ํ•˜๊ธฐ
  • ํŽ˜์ด์Šค๋ถ ๊ณต์œ ํ•˜๊ธฐ
  • ์นด์นด์˜ค์Šคํ† ๋ฆฌ ๊ณต์œ ํ•˜๊ธฐ