用java写一个密钥
展开全部
简单的每位上的数减去2加密
import java.util.Scanner;
import java.util.regex.Pattern;
import java.util.regex.Matcher;
public class Encryption {
public static void main(String[] args) {
System.out.print("请输入数字:");
Scanner sca = new Scanner(System.in);
String line = sca.nextLine();
char[] cha = line.toCharArray();
Pattern pattern = Pattern.compile("[0-9]*");
Matcher isNum = pattern.matcher(line);
if(isNum.matches()){
for(int i=0;i<cha.length;i++){
int j= Integer.parseInt(String.valueOf(cha[i]));
if(j<2){
j=j+10;
}
j=j-2;
System.out.print(j);
}
}else System.out.println("输入必须是数字!");
}
}
import java.util.Scanner;
import java.util.regex.Pattern;
import java.util.regex.Matcher;
public class Encryption {
public static void main(String[] args) {
System.out.print("请输入数字:");
Scanner sca = new Scanner(System.in);
String line = sca.nextLine();
char[] cha = line.toCharArray();
Pattern pattern = Pattern.compile("[0-9]*");
Matcher isNum = pattern.matcher(line);
if(isNum.matches()){
for(int i=0;i<cha.length;i++){
int j= Integer.parseInt(String.valueOf(cha[i]));
if(j<2){
j=j+10;
}
j=j-2;
System.out.print(j);
}
}else System.out.println("输入必须是数字!");
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询