title: remove duplicate characters from a string
body: <pre><code>import java.util.Scanner;
  
  public class StringWithoutDuplicate {
  
      public static void stringWithoutDuplicate(String s1)
      {
          int n = s1.length();
          int i = 0;
          while(i&lt;n)
          {
              if(s1.charAt(i) == s1.charAt(i+1))
              {
                  if(s1.charAt(i) == s1.charAt(n-1))
                  {
                      System.out.println(s1.charAt(i));
                  }
                  i++;
              }
              else if(s1.charAt(i) != s1.charAt(i+1))
              {
                  if(s1.charAt(i) == s1.charAt(n-1))
                  {
                      System.out.println(s1.charAt(i));
                  }
                   System.out.println(s1.charAt(i));;
                  i++;
              }
          }
      }
  
      public static void main(String[] args) {
          Scanner s =  new Scanner(System.in);
          s.useDelimiter(",");
          String s1 = s.next();
  
          System.out.println(s1);
  
          stringWithoutDuplicate(s1);
  
      }
  }
  </code></pre>
  
  <p>The code is giving the output but with an exception
  please tell me the error in my code and ways to correct it.
  I don't want to change the logic of my code so kindly solve it using this logic only.</p>