编写一道ExtractString程序,从字符串“Seize the Day”中提取单词“the”和“Day”.

来源:百度知道 编辑:UC知道 时间:2024/06/22 01:02:42

public class ExtractString {
public String text = "Seize the Day";
public String the = null;
public String Day = null;

public void extract() {
char[] theArray = new char[3];
for (int i = 6; i < 9; i ++)
theArray[i - 6] = text.charAt(i);
the = new String(theArray);

char[] DayArray = new char[3];
for (int i = 10; i < 13; i ++)
DayArray[i - 10] = text.charAt(i);
Day = new String(DayArray);

System.out.printf("%s, %s", the, Day);
}

public static void main(String args[])
{
ExtractString test = new ExtractString();
test.extract();
}
}