public class jiami {
// 对密码进行加密操作。 比如 1983.
public static void main(String[] args) {
System.out.println(result(1983)); //结果为8346
}
public static String result(int number){ //number用来输入数字
int[] numbers=split (number); //1.建一个numbers数组,方便拆分数字并运算。 (这行操作是调一个split的方法)
// 假设输入的number = 1 9 8 3
//2.遍历数组numbers,并对其进行运算加密
for (int i = 0; i < numbers.length; i++) {
numbers[i] = (numbers[i]+5)%10;
}
//3.反转numbers[i]
fanzhuan(numbers); //创建fanzhuan方法
//4.把计算的数字连接起来
String lianjie = "";
for (int i = 0; i < numbers.length; i++) {
lianjie+=numbers[i];
}
return lianjie;
}
public static void fanzhuan(int[] numbers) { //此为反转方法
for (int i = 0, j =numbers.length-1; i <j; i++,j--) {
int temp = numbers[j];
numbers[j] = numbers[i];
numbers[i] = temp;
}
}
public static int[] split(int number) { //此为split方法
//做一个数组,方便拆分数字。(方法)
int numbers[] = new int[4];
//假设输入的number = 1983
numbers[0] = number/1000;
numbers[1]= number/100%10;
numbers[2]= number/10%10;
numbers[3]= number%10;
return numbers;
}
}
--------------------------------------------------------------------
第一步的其它编写。
public static String result(int number){ //number用来输入数字
// int[] numbers=split (number);
// 假设输入的number = 1 9 8 3
int numbers[] = new int[4]; //1.建一个numbers数组,方便拆分数字并运算。 !!!此为不采用方法直接写。
//假设输入的number = 1983
numbers[0] = number/1000;
numbers[1]= number/100%10;
numbers[2]= number/10%10;
numbers[3]= number%10;
//2.遍历数组numbers,并对其进行运算加密
for (int i = 0; i < numbers.length; i++) {
numbers[i] = (numbers[i]+5)%10;
}
...
标签:10,加密,数字,int,number,static,numbers,public From: https://www.cnblogs.com/nulicheng/p/17855623.html