Java 程序将整数和字符串连接
要将整数与字符串值连接起来,需要使用 + 操作符。
假设字符串如下。
String str = "Demo Text";
现在,我们将整数值连接到上述字符串。
String res = str + 1 + 2 + 3 + 4 + 5;
示例
public class Demo { public static void main(String[] args) { String str = "Demo Text"; System.out.println("String = "+str); String res = 99 + 199 + 299 + 399 + str; System.out.println(res); } }
输出
String = Demo Text 996Demo Text
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP