Upload files to "OOP/Java/Lab/Week9"
This commit is contained in:
parent
e9a4ce08c7
commit
cd43a87e9b
5 changed files with 99 additions and 0 deletions
27
OOP/Java/Lab/Week9/replacing.java
Normal file
27
OOP/Java/Lab/Week9/replacing.java
Normal file
|
@ -0,0 +1,27 @@
|
|||
import java.util.Scanner;
|
||||
class replacing{
|
||||
public static void main(String[] args) {
|
||||
Scanner in=new Scanner(System.in);
|
||||
System.out.println("Enter the Lines...");
|
||||
String str=in.nextLine();
|
||||
str.trim();
|
||||
System.out.println("Enter the word to be removed");
|
||||
String word=in.nextLine();
|
||||
StringBuffer strbuf= new StringBuffer(str);
|
||||
if(str.contains(word))
|
||||
{
|
||||
|
||||
int index=str.indexOf(word);
|
||||
int wlen=word.length();
|
||||
String
|
||||
String rep="";
|
||||
for(int i=0;i<wlen;i++)
|
||||
{
|
||||
rep+="*";
|
||||
}
|
||||
strbuf.replace(index,index+wlen,rep);
|
||||
}
|
||||
System.out.println("Replaced String=\n"+strbuf);
|
||||
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue