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