Advertisement
ffpaladin

Unique Chars (has repeated chars)

Sep 28th, 2015
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.46 KB | None | 0 0
  1.  
  2. public class UniqueLetters {
  3.     public static void main (String args[]) {
  4.         System.out.println(hasUnique("abc"));
  5.         System.out.println(hasUnique("abca"));
  6.         System.out.println(hasUnique("a"));
  7.     }
  8.    
  9.     public static boolean hasUnique (String word) {
  10.        
  11.         if (word.length() > 1)
  12.             for (int i=0; i<word.length()-1; i++) {
  13.                 for (int j=i+1; j<word.length(); j++)
  14.                     if (word.charAt(i) == word.charAt(j))
  15.                         return false;
  16.             }
  17.        
  18.         return true;
  19.     }
  20.  
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement