/*
将本字符串a="this is a test of java"转换成一个字符串数组,要求每个数组元素都是一个有意义的额英文单 词, 并输出到控制台
*/
import java.util.Arrays;
import java.util.concurrent.SynchronousQueue;
public calss ZuoYe15
{
public void stringArray(StringBuffer a)
{
int count=1;
for(int i=0;i<a.length();i++)
{
if(a.charAt(i)==' ')
{
count++;
a.setCharAt(i,'*');
}
}
System.out.println(a);
char [][] b=new char[count][];
label1:
for(int i=0;i<b.length;i++)
{
for(int j=0;j<a.length();j++)
{
if(j==a.indexOf("*"))
{
String asd=a.substring(0, j);
b[i]=asd.toCharArray();
/**
* 调试代码
*/
System.out.println("delete before:"+i+":"+a);
a.delete(0, j+1);
/**
* 调试代码
*/
System.out.println("deleted:"+i+":"+a);
}
String b1=a+"";
if(!b1.contains("*"))
{
b[i]=((a.substring(0, a.length()).toCharArray()));
break label1;
}
}
}
for(int i=0;i<b.length;i++)
{
for(int j=0;j<b[i].length;j++)
{
System.out.print(b[i][j]);
}
System.out.println();
}
}
public static void main(String[] args)
{
ZuoYe15 aaa=new ZuoYe15();
StringBuffer a=new StringBuffer("this is a test of java");
aaa.stringArray(a);
}
}