|
|
|
|
32
|
result = result + phrase.substring(firstSpaceIndex+1, firstSpaceIndex+2);
|
32
|
result = result + phrase.substring(firstSpaceIndex+1, firstSpaceIndex+2);
|
33
|
phrase = phrase.substring(0,firstSpaceIndex) + phrase.substring(firstSpaceIndex+1);
|
33
|
phrase = phrase.substring(0,firstSpaceIndex) + phrase.substring(firstSpaceIndex+1);
|
34
|
firstSpaceIndex = phrase.indexOf(" ");
|
34
|
firstSpaceIndex = phrase.indexOf(" ");
|
35
|
- System.out.print(result);
|
|
|
36
|
}
|
35
|
}
|
37
|
return result;
|
36
|
return result;
|
38
|
}
|
37
|
}
|
|
|
|
|
50
|
* @return the encrypted string by shifting each character by three character
|
49
|
* @return the encrypted string by shifting each character by three character
|
51
|
*/
|
50
|
*/
|
52
|
public String encrypt(String word) {
|
51
|
public String encrypt(String word) {
|
53
|
- return null;
|
|
|
|
|
52
|
+ String alphabet = "abcdefghijklmnopqrstuvwxyzabcde";
|
|
|
53
|
+ String codedWord = "";
|
|
|
54
|
+ for (int i=0; i<word.length(); i++) {
|
|
|
55
|
+ int alphaIndex = alphabet.indexOf(word.charAt(i));
|
|
|
56
|
+ codedWord += String.valueOf(alphabet.charAt(alphaIndex+3));
|
|
|
57
|
+ }
|
|
|
58
|
+ return codedWord;
|
54
|
}
|
59
|
}
|
55
|
}
|
60
|
}
|