找不到符号println

6

我今天刚开始一个新的Java项目,但是在使用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

编译器的输出
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出问题的情况。


3
将逗号替换为加号。 - andy256
3个回答

13
你应该使用+而不是,来连接字符串。
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");

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接