horsemanship世界

星期一, 3月 06, 2006

Lab3

display 1.7

public class work
{
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("01234567890123456789012");
System.out.println(sentence);
System.out.println("The word \"hate\"start at index "+position );
sentence =sentence.substring(0, position)+"adore"+ending;
System.out.println("The changed staring is:");
System.out.println(sentence);
}
}

結果:
01234567890123456789012
I hate text processing!
The word "hate"start at index 2
The changed staring is:
I adore text processing!
---------------------------------------------------------------------------------------------

Project 5

public class work
{
public static void main(String[] args)
{
String sentence = "I hate you!";
int position = sentence.indexOf("hate");
String ending =
sentence.substring(position + "hate".length());
System.out.println("The line of \"hate\"to be changed is:");
System.out.println(sentence);
sentence = sentence.substring(0, position) + "love"+ ending;
System.out.println("I have rephrased that line to read :");
System.out.println(sentence);
}
}

結果:
The line of "hate"to be changed is:
I hate you!
I have rephrased that line to read :
I love you!

0 Comments:

張貼留言

<< Home