整合了一川的后半部分- public class encryption{
- public static void main(String args[]) {
- getNumber(1234567);
- }
- public static void getNumber(int number) {
- int a = number / 1000000;
- int b = number % 1000000 / 100000;
- int c = number % 100000 / 10000;
- int d = number % 10000 / 1000;
- int e = number % 1000 / 100;
- int f = number % 100 / 10;
- int g = number % 10;
- int arr[] = new int[] { a, b, c, d, e, f, g };//搞出来的存到数组里
- EncryptData(arr);//倒序,加5 取模10 第1和最后一个换位
- PrintArray(arr);//遍历数组
- }
- public static void EncryptData(int[] arr) {
- for (int i = 0; i < arr.length / 2; i++) {
- int temp;
- temp = arr[i];
- arr[i] = arr[arr.length - 1 - i];
- arr[arr.length - 1 - i] = temp;
- }
- for (int i = 0; i < arr.length; i++) {
- arr[i] = (arr[i] + 5) % 10;// 每位数加5,后模10
- }
- int temp;
- temp = arr[0];
- arr[0] = arr[arr.length - 1];
- arr[arr.length - 1] = temp;// // 第一位和最后一位互换
- }
- public static void PrintArray(int[] arr) {
- for (int i = 0; i < arr.length; i++) {
- System.out.print(arr[i] + " ");
- }
- System.out.println();
- }
- }
复制代码 |