2013-07-30 46 views
3

我今天剛剛開始一個新的java項目,並且遇到了println的問題。這是我的主要方法:找不到符號println

public static void main(String[] args) { 
    String stringNumGuards = JOptionPane.showInputDialog("How any guards do you have?"); 
    int numGuards = Integer.parseInt(stringNumGuards); 
    Controller headGuard = new Controller(); 
    System.out.println("You have ", numGuards, " guards"); 
} //main 

javac的輸出

Controller.java:10: cannot find symbol 
symbol : method println(java.lang.String,int,java.lang.String) 
location: class java.io.PrintStream 
     System.out.println("You have ", numGuards, " guards"); 

我做了什麼錯?我以前從來沒有遇到與println有關的問題。

+2

用+符號替換逗號 – andy256

回答

10

您連接字符串與+,

System.out.println("You have ", numGuards, " guards"); 

應該成爲

System.out.println("You have " + numGuards + " guards"); 
3

你需要讓你的println這樣的:

System.out.println("You have " + numGuards + " guards"); 

這樣可以將一個字符串變量你把它放在println語句中。

0

在java中,你必須給+符號代替,println方法來連接字符串。所以你必須這樣輸入。

System.out.println("You have " + numGuards + " gurads");