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 = str + 1 + 2 + 3 + 4 + 5; System.out.println(res); } }
輸出
String = Demo Text Demo Text12345
廣告