forked from regression1607/HacktoberFest
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReplaceWord.java
More file actions
25 lines (19 loc) · 752 Bytes
/
Copy pathReplaceWord.java
File metadata and controls
25 lines (19 loc) · 752 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import java.util.Scanner;
class ReplaceWord {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String sentence, word, replacement;
System.out.println("Enter the string:");
sentence = scanner.nextLine();
System.out.println("Enter the word to be searched:");
word = scanner.nextLine();
System.out.println("Enter the word to be replaced:");
replacement = scanner.nextLine();
String replacedSentence = sentence.replace(word, replacement);
if (replacedSentence.equals(sentence)) {
System.out.println("The word " + word + " not found");
} else {
System.out.println(replacedSentence);
}
}
}