上机实践五自测题2

作者在 2011-12-21 09:34:31 发布以下内容
import java.util.*;
class GetToken{
    String[] s;
    public String getToken(int index,String str){
        StringTokenizer fenxi=new StringTokenizer(str);
        int number=fenxi.countTokens();
        System.out.println(number);
        s=new String[number+1];
        int k=1;
        while(fenxi.hasMoreTokens()){
            String temp=fenxi.nextToken();
            s[k]=temp;
            k++;
        }
        if(index<=number)
            return s[index];
        else
            return null;
    }
}
public class E{
    
    public static void main(String[] agrs){
        String str="We Love This Game";
        GetToken token=new GetToken();
        String s1=token.getToken(2,str),
                s2=token.getToken(4,str);
        System.out.println(s1+":"+s2);
        
    }
}
 
java codes | 阅读 922 次
文章评论,共0条
游客请输入验证码
浏览18055次
最新评论