在Java中,可以使用加号(+)来连接字符串和数字。例如:
```java
int num = 10;
String str = "The number is " + num;
System.out.println(str);
```
这将输出:
```
The number is 10
```
如果要将数字转换为字符串再拼接,可以使用`String.valueOf()`方法或者`Integer.toString()`方法。例如:
```java
int num = 10;
String str = "The number is " + String.valueOf(num);
System.out.println(str);
```
或者:
```java
int num = 10;
String str = "The number is " + Integer.toString(num);
System.out.println(str);
```
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读:c语言字符串和数字怎么拼接