For Details of The Program: CLICK HERE
import
java.io.*;
import
java.util.*;
class
Str3
{
int
x,i=0,c;
String
s,st[],word;
StringTokenizer
stk;
BufferedReader br=new BufferedReader(new
InputStreamReader(System.in)); public void takeString() throws Exception {
System.out.println("Enter
the Sentence:");
s=br.readLine().toUpperCase();
c=s.length();
if(s.charAt(c-1)!='.'
&& s.charAt(c-1)!='?'&& s.charAt(c-1)!='!')
{
System.out.println("Invalid
Input.");
return;
}
stk=new
StringTokenizer(s,".?! ");
x=stk.countTokens();
st=new
String[x];
while(stk.hasMoreTokens())
{
st[i++]=stk.nextToken().trim();
}
s="";
System.out.println("Enter the word to be
deleted:");
word=br.readLine().toUpperCase();
System.out.println("Enter
the position of the word:");
c=Integer.parseInt(br.readLine());
if(!st[c-1].equals(word))
{
System.out.println("Invalid
location.");
return;
}
for(i=0;i
< c ; i++)
{
if(i!=c-1)
s=s+"
"+st[i];
}
s=s+".";
System.out.println("OUTPUT:"+s);
}
public
static void main(String args[])throws Exception
{
Str3
ob=new Str3();
ob.takeString();
}
}
No comments:
Post a Comment