2012-04-02 74 views
1

簡單替代密碼。簡單替代密碼

我試圖做一個循環構造,將循環通過一個字符串,並在同一時間寫入到另一個字符串。遇到空間時,我無法跳過它。有人能幫我解決這個問題嗎?

String translate = "";//create empty string 
int xxx = 0; //initialise counter 
while(xxx < text.length()) { //based on the original length of input text 
if (text.charAt(xxx) != ' '){ //if no white space do this 
translate = translate.concat(Character.toString((s2.charAt(copyS.indexOf(text.charAt(xxx)))))); 

} else { //if there is white space do this. (I'm unsure how to make it skip?) 

} 
xxx++; 
} 

回答

2

如果您想跳過空格,那麼只需刪除else塊即可。如果你想保持它,再加入

translate = translate.concat(' '); 

- 我的回答使用您使用的算法相同的模式 - 這是非常低效的。如果你想構建一個字符串,那麼請看看StringBuilder類。