開始使用免費開始

字串串接

在程式設計中,合併文字是最常見的操作之一。無論你是在建立個人化訊息、產生報表,或是格式化輸出,你都會經常使用字串串接。現在就來練習這項關鍵技能!

本練習屬於課程

Java 入門

檢視課程

練習說明

  • 使用字串串接,將 itemName 加到第一個印出語句中。
  • itemPrice 加到第二個印出語句中。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

class ConcatenateAway {
    public static void main(String[] args) {
    
        String itemName = "VR Headset";
        int itemPrice = 599;
        
        // Add itemName to the printout statement
        System.out.println("Item is " + ____);
        
        // Add itemPrice to the printout statement
        System.out.println("Price is " ____ ____);
    }
}
編輯並執行程式碼