JAVA

星期一, 三月 06, 2006

把hate改成love

package aaa;


public class Untitled1 {
public static void main(String[] args)
{
String sentence="I hate text processing!";
int position=sentence.indexOf("hate");
String ending=
sentence.substring(position+"hate".length());
System.out.println(sentence);
sentence=sentence.substring(0,position)+"love"+ending;
System.out.println("The changed string is:");
System.out.println(sentence);

}
}

程式結果
I hate text processing!

The changed string is:

I love text processing!

0 Comments:

发表评论

<< Home