所以我一直在試圖做出這個簡單的加密程序,但我似乎無法弄清楚一些事情。我需要輸入短語是使用正則表達式替換子字符串
This is a very big morning.
當我進入它,雖然它返回字符串
This is a ag',rery dug>?/ijeb..w ssadorninjeb..w
相反,我回到
This is a ajedg>P/..w',rery dg>P/ijedg>P/..w ssadorninjedg>P/..w
我不明白爲什麼,以及如何解決它?我一直在學習java一個月左右,所以我仍然很新鮮,如果有類似的問題已經得到解答,請在那裏與我聯繫,我將刪除這篇文章。
下面的代碼:
import static java.lang.System.out;
import java.util.Scanner;
class Encryption {
public static void main(String[] args) {
Scanner userInput = new Scanner(System.in);
Crypto user1 = new Crypto();
out.print("Please enter in a sentence: ");
String user = userInput.nextLine();
user1.encrypt(user);
out.print(user1.getEncrypt());
}
}
public Crypto() { }
public String myEn;
public void encrypt(String Sentence) {
myEn = Sentence.replaceAll("v","ag',r")
.replaceAll("m" , "ssad")
.replaceAll("g" , "jeb..w")
.replaceAll("b" , "dg>P/");
}
public String getEncrypt() {
return myEn;
}
}