Answers for "first none duplicated char"

0

first none duplicated char

import java.util.Scanner;

public class FirstDuplicate
{
    private static Scanner scanner = new Scanner(System.in);
    public static void main(String[] args)
    {
        System.out.println("Enter random chars");
        String s = new String(scanner.nextLine());
        findTheFirstDublicate(s);

    }
    private static boolean findTheFirstDublicate(String s)
    {
        int[] arr = new int[26];

        for(int i=0 ; i<s.length() ; ++i)
        {
          int c =  s.charAt(i)-'a';
          ++arr[c];
        }
        pint(arr);
        return false;
    }

    private static void pint(int[] arr){
        int i = 0 ;
        while(i < arr.length){
            if(arr[i] == 1){
                System.out.println("First none duplicated letters "+((char)(i+'a')));
            }
            ++i;
        }
    }
}
Posted by: Guest on August-06-2021

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language