0

这是我返回的,我不知道是什么错误:找不到符号

    C:\Users\testuser\Desktop\TestFile.java:33: error: cannot find symbol
                            Scanner sc = new Scanner(System.in);
                            ^
      symbol:   class Scanner
      location: class TestFile
    C:\Users\testuser\Desktop\TestFile.java:33: error: cannot find symbol
                            Scanner sc = new Scanner(System.in);
                                             ^
      symbol:   class Scanner
      location: class TestFile
    C:\Users\testuser\Desktop\TestFile.java:44: error: cannot find symbol
                            String[] tabs = prep.Split(" ");
                                                ^
      symbol:   method Split(String)
      location: variable prep of type String
    3 errors

这是我的代码。

public class TestFile {

    String[] preps = {
        "about", "above", "across", "after", "against",
        "along", "among", "around", "at", "before",
        "behind", "below", "beneath", "beside", "between",
        "by", "concerning", "down", "during", "except",
        "for", "from", "in", "inside", "into",
        "like", "near", "of", "onto", "out",
        "over", "through", "to", "toward", "under",
        "up", "upon", "with", "within", "without"
    };

    String[] errorpreps = {
        "will", "would", "shall", "should", "can",
        "could", "may", "might", "must", 
    };

    String[] question = {
    };


    public static void main(String[] args) {

        TestFile f = new TestFile();

        f.generatecode("hi");

    };

    public String generatecode(String code){

        Scanner sc = new Scanner(System.in);
        String inp = sc.nextString();

        String prep = "";

        for (int i=0; i<preps.length+1; i++){ //retuns all inputed things into prep

            prep = preps + preps[i] + " ";

        }

        String[] tabs = prep.Split(" "); //splits the inputed thing and puts it into tab

        for (int f=1; f<tabs.length+1; f++){
            String prox = tabs[f];

            if(prox.contains(".")){
                prep = "Found a .!";
            } else if(prox.contains("?")){
                prep = "Found a ?!";
            } else if(prox.contains("!")){
                prep = "Found a !!";
            } else if(prox.contains(",")){
                prep = "Found a ,!";
            }
        }

        return prep;

    }

    public String printcode(String code){


        return "";

    }

}

现在问题是我对 Scanner 不太了解。我没有导入任何东西。我知道一些关于拆分方法的知识。我无法弄清楚为什么我的语法不正确。我相信其他示例的语法是正确的。

提前致谢。

4

1 回答 1

1

你有两个问题:

  • 您不导入 Scanner 类;如果您不明白为什么需要这样做,请参阅内容。将其放在代码的开头:

    import java.util.Scanner;

  • String.split()是小写。

    你写: String[] tabs = prep.Split(" ");
    应该是: String[] tabs = prep.split(" ");

于 2013-04-10T01:32:18.547 回答