875843
import java.util.Scanner; public class Test密码发生器 { /** * @param args */ public static void main(String[] args) { Scanner scan = new Scanner(System.in); int num = Integer.parseInt(scan.nextLine()); String[] s = new String[num]; for (int i = 0; i < s.length; i++) { s[i] = scan.nextLine(); } String string; for (int a = 0; a < s.length; a++) { char[] c = new char[6]; for (int i = 0; i < s[a].length(); i++) { c[i % 6] += s[a].charAt(i); } for (int i = 0; i < c.length; i++) { string = (int) c[i] + ""; System.out.print(digui(string)); } System.out.println(); } } public static String digui(String s) { int num = 0; if (s.length() == 1) return s; if (s.length() > 1) { for (int i = 0; i < s.length(); i++) { num += Integer.parseInt(s.split("")[i + 1]); } } return digui(num + ""); } }
原文地址:http://blog.csdn.net/tracysilocean/article/details/27229251