ALGORITHM/문제해결

[JAVA] 유니코드 문자

안낭우훗 2018. 8. 11. 17:27

  /*문제: 22
 1) 주어진 문자열의 대문자 알파벳의 개수를 센다.
 2) 실행 및 출력 예:
 >java Test circleofnumbers
 b:1
 c:2
 e:2
 f:1
 i:1

 

  int no = Integer.parseInt(args[0]);

    char ch = 'A'; // A 문자의 유니코드 값이 저장. 0x0041 = 65 = A
    System.out.println((char)(ch + no));
    System.out.println(44032); 
    System.out.println((char)44032); // 가

 

 class Test {

 public static void main(String[] args) throws Exception {
   char[] chars = args[0].toUpperCase().toCharArray();
   int[] counts = new int[26];

   for (int i = 0; i < counts.length; i++) {
       counts[i] = 0;
   }

   for(int i = 0; i < chars.length; i++) {
      counts[chars[i] - 'A']++;
   }
   for (int i = 0; i < counts.length; i++) {
     if (chars[i] <= 0) {
       continue;
     }
     System.out.printf("%c: %d \n", (char) (i + 'A'), counts[i]);
   }

  }
}