Java Blog

 
 
 
  import java.io.*;

  class DeleteMethod
  {
       void del(String str,int m)
       {
              char c;
              String s1,s2;
              int len=str.length();
              if (m>len)
              {
                  System.out.println(\"INVALID POSITION \");
                  System.exit(1);
              }
              else
              {
//                  c=str.charAt(m);
                  s1=str.substring(0,m-1);
                  s2=str.substring(m);
                  System.out.print(\"Your Updated String is  \"+s1+s2);
             }
       }
  };

class Delete 
{
    public static void main(String args[]) 
    {
       DeleteMethod obDM = new DeleteMethod();
       String str,s;
       int m;

       try{
            BufferedReader obj = new BufferedReader(new InputStreamReader

(System.in));
            System.out.print(\"\\nEnter String : \");
            System.out.flush();
            str=obj.readLine();

            System.out.print(\"Enter character position which you want to 

delete : \");
            System.out.flush();
            s=obj.readLine();
            m=Integer.parseInt(s);

             obDM.del(str,m);
            }
        catch(Exception e)
        {}

    }
}

 
 
Didn't find what you were looking for? Find more on Program to delete mth element from an input string