Java: Print a unique character in a string

前端 未结 17 1172
长情又很酷
长情又很酷 2021-01-03 00:03

I\'m writing a program that will print the unique character in a string (entered through a scanner). I\'ve created a method that tries to accomplish this but I keep getting

17条回答
  •  囚心锁ツ
    2021-01-03 00:38

    import java.util.*;
    import java.lang.*;
    class Demo
    {
    public static void main(String[] args)
    {
    
    Scanner sc=new Scanner(System.in);
    System.out.println("Enter String");
    String s1=sc.nextLine();
     try{
    HashSet h=new HashSet();
    for(int i=0;i itr=h.iterator();
      while(itr.hasNext()){
       System.out.println(itr.next());
        }
        }
        catch(Exception e)
        {
        System.out.println("error");
        }
    }
    }
    
        

    提交回复
    热议问题