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
廣告