Re: [問題] 如何簡化此程式?
try String.toUpperCase() and String.toLowerCase()
※ 引述《dorng (東)》之銘言:
: 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: 59.116.168.9
討論串 (同標題文章)
以下文章回應了本文:
完整討論串 (本文為第 2 之 7 篇):