India’s Best Job Seekers and Training Platform Forums Java Problems set Given a string, print out all of the unique…

Tagged: , ,

  • Given a string, print out all of the unique…

     Akash  updated 11 months, 2 weeks ago 2 Members · 2 Posts
  • Akash 

    Administrator
    at

    Given a string, print out all of the unique characters and the number of times it appeared in the string

  • Akash 

    Administrator
    at

    class Palindrome

    {

    public static void uniqueCharacters(String test) {

    String temp = “”;

    for (int i = 0; i < test.length(); i++) {

    char ch = test.charAt(i);

    if (temp.indexOf(ch) == -1) {

    temp = temp + ch;

    } else {

    temp.replace(String.valueOf(ch),””);

    }

    }

    System.out.println(temp + ” “);

    }}

    //Driver code

    public static void main(String args[])

    {

    Palindrome p=new Palindrome();

    System.out.println(“Enter the string”);

    Scanner scan=new Scanner(System.in);

    String str=scan.nextLine();

    p.uniqueCharacters(str);

Log in to reply.

Original Post
0 of 0 posts June 2018
Now
KodNest Training New Batch is starting on 02nd November 2020. Attend one week free demo classes.Register Now

New Report

Close