Sunday, 15 December 2013

Get the first non repeating alphabet from the given string by the user

public class FirstNonReapeating {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws IOException {
        // TODO code application logic here
        String str = "rrrrrraaaaavvvvvi";
  int[] count = new int[128];
  char[] charArr = str.toLowerCase().toCharArray();
  for (char c : charArr) {
   count[c]++;
  }
  for (char c : charArr) {
   if (count[c] == 1) {    
    System.out.println("First Non repeated character is : " + c);
    break;
   }
  }
       
    }
}

No comments:

Post a Comment