2012-04-02 7 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クラスをご覧ください。