Cannot find symbol println
Asked Answered
G

3

6

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.

Gernhard answered 30/7, 2013 at 22:50 Comment(1)
Replace the commas with + signsCarrew
C
13

You concatenate Strings with + not ,

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

Should become

System.out.println("You have " + numGuards + " guards");
Correlate answered 30/7, 2013 at 22:51 Comment(0)
C
3

You need to have your println like this:

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

This concatenates a string with a variable that you put in the println statement.

Corps answered 30/7, 2013 at 22:52 Comment(0)
A
0

In java, you have to give + symbol instead of , in the println method to concatenate the strings. So you have to enter like this.

System.out.println("You have " + numGuards + " gurads");
Andean answered 23/10, 2017 at 8:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.