arrays - How will i get single letters on any word for this code (java) -


this code need output of flexibility of words what's lacking whit code? please.

with spacing words , type of words. code our basic programming please me.

    string str = "programming";     char searchchar;     int counter = 0;      (int = 0; < str.length(); i++) {         searchchar = str.charat(i);         i++;          (int j = 0; j < str.length(); j++) {             if (searchchar == str.charat(j)) {                 counter = counter + 1;                 continue;             }         }          if (counter > 1) {             system.out.println(searchchar);         }          counter = 0;     } 

according comment, want count frequency of letters in string. use map keeping count of letters in it. it'd simple.

map<character, integer> charfrequency = new hashmap<>(); string str = " programming";  // count frequency of letters (char ch : str.tochararray()) {     integer val = charfrequency.get(ch);     if (val != null) {         charfrequency.put(ch, val + 1); // letter exists in map, increase frequency 1     } else {         charfrequency.put(ch, 1); // letter not exist in map, set frequency 1     } }  // print frequencies of letters (map.entry<character, integer> entry : charfrequency.entryset()) {     character ch = entry.getkey();     integer frequency = entry.getvalue();     system.out.println("'" + ch + "' has frequency = " + frequency); } 

Comments