import java.util.Scanner;
class TranPassword {//将四位整数加密
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入要加密的内容:");
int n = sc.nextInt(),ge,shi,bai,qian;
//求每位数字
ge = n % 10;
shi = n / 10 % 10;
bai = n / 100 % 10;
qian = n / 1000 % 10;
//每位数字都加上该数字与2的余数
ge = ge + ge % 2;
shi = shi + shi % 2;
bai = bai + bai % 2;
qian = qian + qian % 2;
//再将第一位和第四位交换
int temp;
temp = ge;
ge = qian;
qian = temp;
//第二位与第三位交换
temp = shi;
shi = bai;
bai = temp;
System.out.println("加密后的结果:");
System.out.println("" + qian + bai + shi + ge);
}
}
|