[問題] 如何簡化此程式?

看板java作者 (東)時間18年前 (2006/06/01 22:13), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/7 (看更多)
public class Et01 { public static void main (String[] args) throws java.io.IOException { java.io.BufferedReader keyin; keyin = new java.io.BufferedReader(new java.io.InputStreamReader(System.in)); System.out.print("請輸入五個英文字元(大小寫不拘):"); String K = keyin.readLine(); char[] X = K.toCharArray(); int L = (int)K.length(); f1:{ if (L == 5) { for (int i = 0; i <= 4; i++) { int c = (int)K.charAt(i); if (64 >= c || (93 <= c && c <= 96) || 125 <= c) { System.out.print("僅能接受英文字元"); break f1;  } } for (int i = 0; i <= 4; i++) { int c = (int)K.charAt(i); if (65 <= c && c <= 92) X[i] = (char)(c+32); else if (97 <= c && c <= 124 ) X[i] = (char)(c-32); System.out.print(X[i]); } } else System.out.println("輸入長度錯誤"); } } } 上述程式是用來將英文字元大小寫互換。 請問各位大大,小弟該如何簡化code呢@@? -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 220.134.179.89
文章代碼(AID): #14VlNxyW (java)
討論串 (同標題文章)
文章代碼(AID): #14VlNxyW (java)