扫描仪问题。分裂问题。找不到符号 - java

时间:2013-04-10 01:29:28

标签: java

这是我得到的,我无法弄清楚是什么错误:找不到符号

    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了解不多。我没有进口任何东西。我知道一些分裂方法。我无法弄清楚为什么我的语法不正确。我相信这是正确的语法与其他例子有关。

提前致谢。

1 个答案:

答案 0 :(得分:1)

你有两个问题:

  • 您不导入Scanner类;如果您不理解为什么需要,请参阅this。把它放在代码的开头:

    import java.util.Scanner;

  • String.split()是小写的。

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