문자열을 주어 같은 자모의 횟수를 찾아내다

2054 단어 문자열
import java.util.HashMap; 02 03 04 public class TestArray { 05 06 /** 07 * 08 * @param args 09 */ 10 public static void main(String[] args) { 11 String inputstr = "abcbssssssssssss" ; 12 char [] array_input = inputstr.toCharArray(); 13 HashMap<Character,Integer> map = new HashMap<Character,Integer>(); 14 for ( int i= 0 ;i<array_input.length;i++){ 15 Character row = array_input[i]; 16 //System.out.println(row); 17 if (map.containsKey(row)){ // key value 1 18 Integer count = map.get(array_input[i])+ 1 ; 19 map.remove(row); 20 map.put(row, count); 21 } else { 22 map.put(row, 1 ); 23 } 24 } 25 System.out.println(map); 26 27 } 28 29 30 }

좋은 웹페이지 즐겨찾기