- import java.util.Scanner;
- /*
- * 思路:
- * 通过Scanner扫描System.in完成键盘录入
- * private cutNum()方法录入将明文拆分 那么索引由小到大,分别表式每个数的数位的大小
- * 如 arr[0]-----个位
- * arr[2]-------十位
- * ......
- * 題目指出,
- * private invertedOder() 该方法将这个数进行倒序
- *
- *
- * private jiaMi() 将传入的数组的每一个数加5并模十,再将每个数。arr[0]与arr[Maxindex]交换数据。
- *
- * 未了保证安全性将这三个方法制定为ptivate的。
- *
- * */
- //@SuppressWarnings("all")
- public class JiaMi {
- int text;
- int password;
- /*
- * // text=123456; // arr[0]=6; // arr[1]=5; //
- */
- private int[] cutNum() {
- int text = this.text;
- int[] temp = new int[8];
- int[] arr = null;
- int cont = 0;
- while (text > 0) {
- temp[cont] = text % 10;
- text /= 10;
- cont++;
- }
- if (cont >= 8) {
- throw new RuntimeException("超过8位数");
- }
- arr = new int[cont];
- for (int i = 0; i <= cont - 1; i++) {
- arr[i] = temp[i];
- }
- return arr;
- }
- private int[] invertedOder(int[] arr) {
- int[] invertedArr = new int[arr.length];
- for (int i = arr.length - 1, j = 0; i >= 0; i--, j++) {
- invertedArr[j] = arr[i];
- }
- return invertedArr;
- }
- private int jiaMi(int[] arr) {
- int pass = 0;
- for (int i = 0; i < arr.length; i++) {
- arr[i] = (arr[i] + 5) % 10;
- }
- int tmp = arr[0];
- arr[0] = arr[arr.length - 1];
- arr[arr.length - 1] = tmp;
- pass = arr[arr.length - 1];
- for (int i = arr.length - 2; i > -1; i--) {
- pass *= 10;
- pass += arr[i];
- }
- return pass;
- }
- private int jiaMin() {
- return jiaMi(invertedOder(cutNum()));
- }
- public void setText() {
- Scanner sc = new Scanner(System.in);
- this.text = sc.nextInt();
- }
- public int getpass() {
- password = jiaMin();
- return password;
- }
- public static void main(String[] args) {
- JiaMi jm = new JiaMi();
- jm.setText();
- System.out.println(jm.getpass());
- }
- }
复制代码 |
|