StringApp.detectWord();
 StringApp.detectLetter();这两个是不是你自己定义的方法阿?
在String的API里面好像没有这两个方法阿至于length
改成length()还有chatAt
改成charAt
注意方法名

解决方案 »

  1.   

    那两个是我定义的方法,为什么不能调用呢。我也是了直接detectWord();这样的形式,,还有带参数的形式,都不能被调用.我发现我的java书上,对使用方法讲得比较笼统,例子就一个,具体问题,没有参照。
      

  2.   

    detectWord(java.lang.String[]) 
    你的这两个方法
    参数是String数组
    你有没有传递一个
    String[] 类型的进取阿?
    检查一下是不是你传递了一个String进去而已
      

  3.   

    /*我的源程序有一个定义的字符串,比如"xtj is a king of pop"
    如何用java编出一个程序使得
    1 可输出其任意一部分,即任意单词
    2 定位输出 即可输出任意一个字母
    */class StringApp {
    String sen = "xtj is a king of pop";
    String[] word = {"xtj","is","a","king","of","pop"};

    public static void main(String[] args) {
    int func;
    System.out.println("function select:\n" + "\t\"1\" to select the word you want\n"
                       + "\t\"2\" to select the letter you want");
                       
    if (args.length() > 0)
        func = Integer.parseInt(args[0]);

    switch (func) {
    case 1: StringApp.detectWord();
            break;
    case 2: StringApp.detectLetter();
            break;
            }
            }

    void detectWord(String[] args) {
    int num;
    System.out.println(sen);
    System.out.println(word.length() + "word(s) in this sentence.\n" + 
                       "which one do you prefer to select?");
    if (args.length() > 0)
        num = Integer.parseInt(args[0]);
    System.out.println("The word you selected is" + word[num]);
    }

    void detectLetter(String[] args) {
    int sit;
    System.out.println(sen);
    System.out.println(sen.length() + "letter(s) in this sentence.\n" + 
                       "which one do you prefer to select?");
    if (args.length() > 0)                   
        sit = Integer.parseInt(args[0]);
    System.out.println("The letter you selected is" + sen.charAt(sit));
            }
    }
      

  4.   

    你的
    void detectLetter(String[] args) {
    这些,其实方法里面不一定要有参数的
    由参数也不一定就是
    String[] args如果你这个是在JSP里面调用的话
    就不要用System.out了