2015年1月29日 星期四

java程式設計題目---字母處理【大寫轉小寫小寫轉大寫】

Write the following method that returns a new string in which the uppercase are changed to lowercace and lowercace to uppercase.
EX: enter: aBcD ,output: AbCd。


  1. import java.util.Scanner;
  2.  
  3. public class C1 {
  4.  
  5. public static void main(String[] args)
  6. {
  7. Scanner input = new Scanner(System.in);//提示使用者輸入並輸入字串
  8. System.out.println("請輸入字串");
  9. String a = input.next();
  10. System.out.println(swapCase(a));
  11. }
  12. public static String swapCase(String s)//將字串大轉小,小轉大
  13. {
  14. String u = s.toUpperCase();
  15. String l = s.toLowerCase();
  16. String a = "";
  17. for(int i = 0 ; i < s.length() ; i++ )
  18. {
  19. if(s.charAt(i) != u.charAt(i))
  20. {
  21. a = a + u.charAt(i);
  22. }
  23. else
  24. a = a + l.charAt(i);
  25. }
  26. return a ;//回傳結果
  27. }
  28. }

1 則留言:

  1. 不好意思,我正在開始學習JAVA
    我想挪用大大的教學,自己做練習一遍,然後再PO到我的紀錄網誌上面。
    就像水無痕你一樣
    用部落格的形式督促自己成整

    回覆刪除

Go(Golang)程式語言 設定GCC

下載MSYS2:  https://www.msys2.org/ 安裝 程式開始執行後輸入: pacman -Syu y y 在安裝目錄底下找到msys2.exe,雙擊執行 輸入指令: pacman -Su pacman -S --needed base-devel mingw-...