Re: [問題]今年台銀IT人員招考試題
為啥要寫這裡麻煩??
不就是把 ascII碼都加上位移數就好了嗎 = =?
我改一下你的程式 .
※ 引述《bleed1979 (十三)》之銘言:
public class Encoding {
public static void main(String[] args) {
System.out.println(new Compress().go(65488973,"MEET ME XXX"));
}
}
class Compress {
public String go(int k, String inPutString) {
k=k%26; //一定要看到%你才高興?
char[] inputChar=inPutString.toCharArray();
StringBuffer outputString =new StringBuffer();
for(int i=0;inputChar.length>i;i++){
if(!(inputChar[i]==' ')){
inputChar[i]= (char)((int)inputChar[i] + k);
if(inputChar[i]>'Z'){
inputChar[i]=(char)(inputChar[i]-26); //超過Z要從頭
}
outputString.append(inputChar[i]);
}else{
//有空格要填進去
outputString.append(inputChar[i]);
}
}
return outputString.toString();
}
}
這樣超過Z就從頭啦
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 59.120.109.150
推
11/22 13:59, , 1F
11/22 13:59, 1F
→
11/22 20:08, , 2F
11/22 20:08, 2F
→
11/22 21:43, , 3F
11/22 21:43, 3F
※ 編輯: MephistoH 來自: 59.120.109.150 (11/23 08:03)
→
11/23 13:09, , 4F
11/23 13:09, 4F
→
11/23 13:11, , 5F
11/23 13:11, 5F
※ 編輯: MephistoH 來自: 59.120.109.150 (11/23 14:05)
討論串 (同標題文章)
完整討論串 (本文為第 4 之 5 篇):