Vampire numbers: What I started thinking is to take four digits apart, then free to combine and then multiply, and finally compare to get results, in the Internet to see some of the practice of friends, let me surprised Ah, think of their algorithm also want to look, this way down is no drop
Now post the code:
Package Edu.cqu.main;import java.util.arrays;/** * Problem Description: * Vampire numbers are digits with even numbers that can be multiplied by a pair of numbers, which each contain a number of half-digits of the product, * where The number selected in the initial number can be sorted arbitrarily. * For example: * 1260 = 21 * 60 1827 = 21 * 87 2187 = 27 * 81 * requires the output of all four-digit vampire numbers. * * @author Gabby * */public class Vampirenumber {public static void main (string[] args) {for (int i = 1; i < 100; i++) {for (int j = i+1; J <; J + +) {//only require output four-bit number if (i * j >= 1000) { String a = i + "" + j; String B = i * j + ""; if (equal (A, B)) {System.out.printf ("%d *%d =%d", I, J, I*j); System.out.println (); }}}}}//Determine if two strings contain the same number as private static Boolean equal (string A, string b) { First sort char[] as = A.tochararray (); char[] bs = B.tochararray (); Arrays.sort (AS); Sort Arrays.sort (BS); Sort if (arrays.equALS (AS, BS)) {return true; } return false; }}
Java Programming Idea--vampire number problem