2013-04-10 125 views
0

這是我得到了回來,我想不出有什麼錯誤:無法找到符號掃描儀問題。拆分問題。無法找到符號 - 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瞭解不多。我沒有輸入任何東西。我知道一些關於拆分方法。我無法弄清楚爲什麼我的語法不對。我相信這是正確的語法脫離其他例子。

在此先感謝。

+4

進口java.util.Scanner的; – Abi 2013-04-10 01:30:30

+3

Immeditaly,'String#split'是小寫字母,所以'prep.Split(「」)'應該是'prep.split(「」)' – MadProgrammer 2013-04-10 01:31:23

+0

@Abi:關閉 - 它以小寫字母I輸入。 – 2013-04-10 01:31:23

回答

1

你有兩個問題:

  • 不會導入Scanner類;如果您不明白爲什麼需要,請參見this。你應該在你的代碼的開頭:

    import java.util.Scanner;

  • String.split()是小寫。

    你寫:String[] tabs = prep.Split(" ");
    應該是:String[] tabs = prep.split(" ");

+0

做得好。謝謝。我被賦予了命令但不能導入。 – user2262111 2013-04-10 01:45:33