阅读量:0
在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);
```