2014-03-03 38 views
0

我一直在嘗試幾天來運行此操作,但由於某種原因它沒有經過。這是代碼:強大的文本cmd一直告訴我錯誤找不到符號

public class namegenerator { 
    public static void main(string[] args) { 

    string[] firstnames = {"James", "Philip", "Danny", "Bob", "joshua"}; 

    string[] lastnames = {"Franklin", "Hunter", "Johnson", "Smith", "Jones"}; 

    int onelength = firstnames.length; 
    int twolength = lastnames.length; 

    int rand1 = (int) (Math.random() * onelength); 
    int rand2 = (int) (Math.random() * twolength); 

    String phrase = firstname [rand1] + " " + lastname [rand2]; 

    System.out.println("Your fake name is, " + phrase); 

    } 

} 
+0

有作爲'string'沒有這樣的關鍵字Java ...你的意思是'String' – fge

回答

0

有你的主要方法聲明一個錯字,類名字符串,而不是字符串

public static void main(String args[]) 
2

你有兩個錯誤。

字符串是 「S」,而不是 「S」

而在你String phrase=你沒加 「S」 到 「姓名」

public static void main(String[] args) { 

    String[] firstnames = {"James", "Philip", "Danny", "Bob", "joshua"}; 

    String[] lastnames = {"Franklin", "Hunter", "Johnson", "Smith", "Jones"}; 

    int onelength = firstnames.length; 
    int twolength = lastnames.length; 

    int rand1 = (int) (Math.random() * onelength); 
    int rand2 = (int) (Math.random() * twolength); 

    String phrase = firstnames[rand1] + " " + lastnames[rand2]; 

    System.out.println("Your fake name is, " + phrase); 

}