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.
Hint: You may consider use the methods: indexOf(A_String) and substring(Start, End) in your program.
用抄的
substring a到A
回覆刪除a是整個字串
A是hate
因此substring(0,A)是0~1(不包含2(hate的開頭))
而A+"hate".length() 是代表2+4
因此是從6開始到結束
所以start+"love"+end
是取頭取尾插中間