Advertisement
brilliant_moves

RepeatedLetterCount.java

Jul 31st, 2015
406
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 0.81 KB | None | 0 0
  1. import java.util.Arrays;
  2. import java.util.ArrayList;
  3.  
  4. public class RepeatedLetterCount {
  5.  
  6.     public static void main(String[] args) {
  7.         String input = "Good friend is needed";
  8.         String[] words = input.split(" ");
  9.         int c=0;
  10.         for (int i=0; i<words.length; i++) {
  11.             ArrayList<String> ar = new ArrayList<String>();
  12.             for (int j=0; j<words[i].length(); j++) {
  13.                 c = 1;
  14.                 if (!ar.contains (words[i].substring(j, j+1))) {
  15.                     ar.add(words[i].substring(j, j+1));
  16.                     for (int k=j+1; k<words[i].length(); k++) {
  17.                         if (words[i].charAt(j) == words[i].charAt(k)) {
  18.                             c++;
  19.                         } // if
  20.                     } // for
  21.                     if (c>1) {
  22.                         words[i] += c;
  23.                     } // if
  24.                 } // if
  25.             } // for
  26.             System.out.print(words[i]+" ");
  27.         } // for i
  28.         System.out.println();
  29.     } // main()
  30.  
  31. } // class RepeatedLetterCount
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement