Advertisement
silent-joe

NonRepeatedCharacter

May 27th, 2015
275
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.83 KB | None | 0 0
  1. package ua.silent.nonrepeated;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.IOException;
  5. import java.io.InputStreamReader;
  6. import java.util.Arrays;
  7. import java.util.LinkedList;
  8.  
  9. public class main {
  10.  
  11.     public static void main(String[] args) throws IOException {
  12.         LinkedList<String> string = getInputString();
  13.         Boolean print = printNonReapeatCharacter(string);
  14.         if (!print) {
  15.             printNotNonRepeatedCharacter();
  16.         }
  17.     }
  18.  
  19.     private static LinkedList<String> getInputString() {
  20.         System.out.println("Please enter the string:");
  21.         String[] string = new String[0];
  22.         try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
  23.             string = reader.readLine().split("");
  24.         } catch (IOException e) {
  25.             e.printStackTrace();
  26.         }
  27.         return new LinkedList(Arrays.asList(string));
  28.     }
  29.  
  30.     private static Boolean printNonReapeatCharacter(LinkedList<String> string) {
  31.         Boolean b = true;
  32.         for(int i = 0; i < string.size(); i++){
  33.             b = true;
  34.             String character = string.get(i);
  35.             for(int j = i + 1; j < string.size(); j++){
  36.                 if(character.equalsIgnoreCase(string.get(j))){
  37.                     string.remove(j);
  38.                     b = false;
  39.                     j--;
  40.                 }
  41.             }
  42.             if(b){
  43.                 printFindNonRepeatedCharacter(character);
  44.                 break;
  45.             }
  46.         }
  47.         return b;
  48.     }
  49.  
  50.     private static void printFindNonRepeatedCharacter(String character){
  51.         System.out.println("First non repeated character = " + character);
  52.     }
  53.  
  54.     private static void printNotNonRepeatedCharacter() {
  55.         System.out.println("This string does not contain a non repeated character");
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement