title: how to print duplicate character from string in java
body: <pre><code>import java.util.*;
  public class DuplicateCharacters {
  
      public static void main(String[] args) {
          // TODO Auto-generated method stub
  
          Scanner s = new Scanner(System.in);
          System.out.println("Enter String: ");
          String str = s.nextLine();
  
          for(int i=0;i&lt;str.length()-1;i++)
          {
              for(int j=i+1;j&lt;str.length();j++)
  
              {
              if(str.charAt(i)==str.charAt(j))
              {
  
                  System.out.print(str.charAt(j));
              }
              }
          }
      }
  
  }
  </code></pre>
  
  <blockquote>
    <p>My code works for string contains 2 duplicate character only ..</p>
  </blockquote>
  
  <p>e.g.  suppose input= india it prints i 
      but when input aaa , output = a a a..it should print a once only</p>