In this program the user will enter a sentence and all the punctuation and special characters
in the string will be removed.
Example
Input: This is, a test
Output: This is a test
import java.io.*;
class A
{
String s1,s2;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int i,len;
char ch;
public void take () throws Exception
{
System.out.println("Enter the sentence:");
s1=br.readLine();
len=s1.length();
s2="";
for(i=0;i< len;i++)
{
ch=s1.charAt(i);
if(Character.isLetter(ch)|| Character.isDigit(ch)||ch==' ')
s2=s2+ch;
}
System.out.println("Original sentence="+s1);
System.out.println("Modified sentence="+s2);
}
public static void main(String args[])throws Exception
{
A ob=new A();
ob.take();
}
}
Related Post: BlueJ Programs on String/Sentence
No comments:
Post a Comment