Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Arrays;
- import java.util.ArrayList;
- public class RepeatedLetterCount {
- public static void main(String[] args) {
- String input = "Good friend is needed";
- String[] words = input.split(" ");
- int c=0;
- for (int i=0; i<words.length; i++) {
- ArrayList<String> ar = new ArrayList<String>();
- for (int j=0; j<words[i].length(); j++) {
- c = 1;
- if (!ar.contains (words[i].substring(j, j+1))) {
- ar.add(words[i].substring(j, j+1));
- for (int k=j+1; k<words[i].length(); k++) {
- if (words[i].charAt(j) == words[i].charAt(k)) {
- c++;
- } // if
- } // for
- if (c>1) {
- words[i] += c;
- } // if
- } // if
- } // for
- System.out.print(words[i]+" ");
- } // for i
- System.out.println();
- } // main()
- } // class RepeatedLetterCount
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement