Cannot find symbol println

ellman121 picture ellman121 · Jul 31, 2013 · Viewed 10.3k times · Source

I just started a new java project today, and I'm having a problem with println. Here's my main method:

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

The javac output

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");

What did I do wrong? I've never had problems with println before.

Answer

Kon picture Kon · Jul 31, 2013

You concatenate Strings with + not ,

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

Should become

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