Thursday, October 16, 2014

BlueJ Program Elimination Of Any Particular Character From A Sentence


In this program user will enter any sentence and a particular character and every occurrence of 

the character in the sentence will be eliminated.
  

import java.io.*;
class Sentence
{
 char ch;
 int i,len;
 String s1,s2="";
  BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
  void show() throws Exception
 {
         System.out.print("Enter the sentence: ");
         s1=br.readLine();
         System.out.print("Enter the character: ");
         ch=(char)br.read();
     len=s1.length();
     for(i=0;i< len;i++)
           {
              if(ch!=s1.charAt(i))
              s2=s2+s1.charAt(i);
            }
            System.out.println("\nOriginal Sentence:"+s1);
            System.out.println("\nModified Sentence:"+s2);
  }
         
    public static void main(String args[])throws Exception
    {
         Sentence ob=new Sentence();
         ob.show();
        }
    }
    

Computer Teacher At Burdwan

Sample Input Output   


Enter the sentence: India is awesome

Enter the character: a

Original Sentence:India is awesome


Modified Sentence:Indi is wesome

No comments:

Post a Comment

Subscribe via email

Enter your email address:

Delivered by FeedBurner