System.out.println("请随机输入四位数字(1000~9999)进行加密处理!"); Scanner scanner = new Scanner(System.in); int nextInt = 0; while (true) { nextInt = scanner.nextInt(); if (nextInt >= 1000 && nextInt <= 9999) { break; } else { System.out.println("请输入四位数字(1000~9999)"); } } // 初始数据 int a = nextInt / 1000;//千位 int b = (nextInt / 100) % 10;//百位 int c = (nextInt / 10) % 10;//十位 int d = nextInt % 10;//个位 // 每一位+5,然后替换为该数除以10取余后的结果。 int a1 = (a + 5) % 10; int b1 = (b + 5) % 10; int c1 = (c + 5) % 10; int d1 = (d + 5) % 10; // 将第一位和第四位互换、第2位和第三位互换。 int newA = d1; int newB = c1; int newC = b1; int newD = a1; System.out.println("您输入的数据是:" + nextInt + "加密后的数据是:" + (newA * 1000 + newB * 100 + newC * 10 + newD)); } } 这样的对吗 求指导
点赞 评论
牛客网
牛客网在线编程
牛客网题解
牛客企业服务