小编典典

如何在Java中连接两个字符串?

java

我正在尝试连接Java中的字符串。为什么这不起作用?

public class StackOverflowTest {  
    public static void main(String args[]) {
        int theNumber = 42;
        System.out.println("Your number is " . theNumber . "!");
    }
}

阅读 553

收藏
2020-02-28

共1个答案

小编典典

你可以使用+运算符来连接字符串:

System.out.println("Your number is " + theNumber + "!");

theNumber被隐式转换为String "42"

2020-02-28