728x90
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | public static void main(String[] args) { // TODO Auto-generated method stub Scanner sc = new Scanner(System.in); int N = sc.nextInt(); String s = sc.next(); switch (N) { case 1: String s2 = ""; for(int i=0; i<s.length(); i++) { if('A'<=s.charAt(i) && s.charAt(i)<='Z') { s2+=("_"+String.valueOf(s.charAt(i)).toLowerCase()); } else { s2+=String.valueOf(s.charAt(i)); } } System.out.println(s); System.out.println(s2); System.out.println(String.valueOf(s.charAt(0)).toUpperCase()+s.substring(1)); break; case 2: String s1 = ""; boolean toUpper = false; for(int i=0; i<s.length(); i++) { if(s.charAt(i)=='_') { toUpper = true; } else { if(toUpper) { s1+=String.valueOf(s.charAt(i)).toUpperCase(); toUpper=false; } else s1+=String.valueOf(s.charAt(i)); } } System.out.println(s1); System.out.println(s); System.out.println(String.valueOf(s1.charAt(0)).toUpperCase()+s1.substring(1)); break; case 3: String finS2=""; for(int i=0; i<s.length(); i++) { if('A'<=s.charAt(i) && s.charAt(i)<='Z') { if(i==0) finS2+=(String.valueOf(s.charAt(i)).toLowerCase()); else finS2+=("_"+String.valueOf(s.charAt(i)).toLowerCase()); } else { finS2+=String.valueOf(s.charAt(i)); } } System.out.println(String.valueOf(s.charAt(0)).toLowerCase()+s.substring(1)); System.out.println(finS2); System.out.println(s); break; } } | cs |
'알고리즘 풀이 > 백준' 카테고리의 다른 글
[백준][Java] 9012번 괄호 (0) | 2021.06.26 |
---|---|
[백준][Java] 1157번 단어 공부 (0) | 2021.06.26 |
[백준][Java] 14719번 빗물 (0) | 2019.12.14 |
[백준][Java] 2493번 탑 (0) | 2019.12.11 |
[백준][Java] 14499번 주사위 (0) | 2019.03.28 |