forked from erenuygur/EfficientHouseJava
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQ5.java
More file actions
28 lines (23 loc) · 986 Bytes
/
Q5.java
File metadata and controls
28 lines (23 loc) · 986 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
26
27
28
package homeworks.chapter2;
/*
Write a program that starts with a line of text and then outputs that line of text
with the first occurrence of "hate" changed to "love". For example, a possible
sample output might be
The line of text to be changed is:
I hate you.
I have rephrased that line to read:
I love you.
You can assume that the word "hate" occurs in the input. If the word "hate"
occurs more than once in the line, your program will replace only the first occurrence of "hate". Since we will not discuss input until Chapter 2, use a defined
constant for the string to be changed. To make your program work for another
string, you should only need to change the definition of this defined constant.
*/
public class Q5 {
public static void main(String[] args)
{
java.util.Scanner kb = new java.util.Scanner(System.in);
System.out.print("TEXT:");
String text = kb.nextLine();
System.out.println(text.replace("hate", "love"));
}
}