EX: enter: aBcD ,output: AbCd。
- import java.util.Scanner;
- public class C1 {
- public static void main(String[] args)
- {
- Scanner input = new Scanner(System.in);//提示使用者輸入並輸入字串
- System.out.println("請輸入字串");
- String a = input.next();
- System.out.println(swapCase(a));
- }
- public static String swapCase(String s)//將字串大轉小,小轉大
- {
- String u = s.toUpperCase();
- String l = s.toLowerCase();
- String a = "";
- for(int i = 0 ; i < s.length() ; i++ )
- {
- if(s.charAt(i) != u.charAt(i))
- {
- a = a + u.charAt(i);
- }
- else
- a = a + l.charAt(i);
- }
- return a ;//回傳結果
- }
- }
不好意思,我正在開始學習JAVA
回覆刪除我想挪用大大的教學,自己做練習一遍,然後再PO到我的紀錄網誌上面。
就像水無痕你一樣
用部落格的形式督促自己成整