作者NightPrince (shooting star)
看板java
标题Re: [问题] 如何简化此程式?
时间Thu Jun 1 22:38:26 2006
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