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

更新時間: 30-Jul-2019

8K+ 檢視

職業起航

完成課程獲權威認證

開始
廣告