Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ua.silent.nonrepeated;
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.util.Arrays;
- import java.util.LinkedList;
- public class main {
- public static void main(String[] args) throws IOException {
- LinkedList<String> string = getInputString();
- Boolean print = printNonReapeatCharacter(string);
- if (!print) {
- printNotNonRepeatedCharacter();
- }
- }
- private static LinkedList<String> getInputString() {
- System.out.println("Please enter the string:");
- String[] string = new String[0];
- try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
- string = reader.readLine().split("");
- } catch (IOException e) {
- e.printStackTrace();
- }
- return new LinkedList(Arrays.asList(string));
- }
- private static Boolean printNonReapeatCharacter(LinkedList<String> string) {
- Boolean b = true;
- for(int i = 0; i < string.size(); i++){
- b = true;
- String character = string.get(i);
- for(int j = i + 1; j < string.size(); j++){
- if(character.equalsIgnoreCase(string.get(j))){
- string.remove(j);
- b = false;
- j--;
- }
- }
- if(b){
- printFindNonRepeatedCharacter(character);
- break;
- }
- }
- return b;
- }
- private static void printFindNonRepeatedCharacter(String character){
- System.out.println("First non repeated character = " + character);
- }
- private static void printNotNonRepeatedCharacter() {
- System.out.println("This string does not contain a non repeated character");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement