Java: Print a unique character in a string

前端 未结 17 1179
长情又很酷
长情又很酷 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:30

    how about this :)

    for (int i=0; i< input.length();i++)
        if(input.indexOf(input.charAt(i)) == input.lastIndexOf(input.charAt(i)))
            System.out.println(input.charAt(i) + "  is unique");
    

提交回复
热议问题