Title: Vampire numbers are numbers with an even number of digits that can be multiplied by a pair of numbers, which each contain a number of half-digits of the product, where the number selected from the initial number can be arbitrarily sorted. Numbers ending in two 0 are not allowed, for example, the following numbers are "vampire" numbers:
1260=21*60
1827=21*87
2187=27*81
Write a program to find out 4-digit numbers of all vampires.
/** * <p> Vampire numbers </p> * @author Shockang * */public class Thevampirenumbers {/** * <p> determine if a 4-digit number is a vampire number method &L t;/p> * @param num * @return The first digit of the Boolean */private static boolean isvampire (int num) {int N1=NUM/1000;//4 number of digits int n2= (num -n1*1000)/100;//Second digit int n3= (num-n1*1000-n2*100)/10;//third digit int n4=num-n1*1000-n2*100-n3*10;//digit// Determines whether the number multiplied by numbers is the original number if ((N1*10+N2) * (n3*10+n4) ==num | | (N1*10+N2) * (n4*10+n3) ==num | | (N2*10+N1) * (n3*10+n4) ==num | | (N2*10+N1) * (n4*10+n3) ==num | | (N1*10+N3) * (n2*10+n4) ==num | | (N1*10+N3) * (n4*10+n2) ==num | | (N3*10+N1) * (n2*10+n4) ==num | | (N3*10+N1) * (n4*10+n2) ==num | | (N1*10+N4) * (n2*10+n3) ==num | | (N1*10+N4) * (n3*10+n2) ==num | | (N4*10+N1) * (n2*10+n3) ==num | | (N4*10+N1) * (N3*10+N2) ==num) {return true;} Else{return false;}} public static void Main (string[] args) {for (int i=1000;i< 10000;i++) {if (Isvampire (i)) {System.out.println (i);}}}}
Java Programming Ideas 4th Edition fourth Chapter exercise 10