例子:
package 加密与解密;
import java.util.*;
public class Test{
public void JiaMi(String s){
char[] arr = s.toCharArray();
for(int i=0;i<s.length();i++){
arr[i]+=3;
}
System.out.println(arr);
}
public void JieMi(String s){
char[] arr = s.toCharArray();
for(int i=0;i<s.length();i++){
arr[i]-=3;
}
System.out.println(arr);
}
public static void main(String[] args){
String s1=new String();
String s2=new String();
Test t = new Test();
Scanner reader = new Scanner(System.in);
System.out.println("请输入所要加密的字符串:");
s1=reader.nextLine();
t.JiaMi(s1);
System.out.println("请输入所要解密的字符串:");
s2=reader.nextLine();
t.JieMi(s2);
reader.close();
}
}
结果截图:
时间: 2024-12-13 10:26:27