寫一個 Java 程式將字串中的每個單詞大寫?


你可以使用 String 類的 toUpperCase() 方法將字串中的單詞大寫。此方法會將當前字串的內容轉換為大寫字母。

示例

 即時演示

public class StringToUpperCaseEmp {
   public static void main(String[] args) {
      String str = "string abc touppercase ";
      String strUpper = str.toUpperCase();
      System.out.println("Original String: " + str);
      System.out.println("String changed to upper case: " + strUpper);
   }
}

輸出

Original String: string abc touppercase
String changed to upper case: STRING ABC TOUPPERCASE

更新於:30-Jul-2019

2K+ 次觀看

開啟您的職業

完成課程獲得認證

開始
廣告
© . All rights reserved.