Topic
A vampire number have an even number of digits and are formed by multiplying a pair of numbers containing half the number of Digits of the result. The digits is taken from the original number on any order. Pairs of trailing zeroes is not allowed. Examples include:1260 = 21 * 60, 1827 = 21 * 87, 2187 = 27 * 81. Write A program This finds all the 4-digit vampire numbers. (Suggested by Dan Forhan.)
1 Public classVampirenumber {2 3 Public Static voidMain (string[] args) {4 intA = 0, b = 0, c = 0, d = 0;5 int[] m =New int[12];6 int[] n =New int[12];7 8 for(inti = 1000; I < 9999; i++) {9 //divided into 4 numbersTenA = i/1000; Oneb = (I-A * 1000)/100; Ac = (I-A * 1000-b * 100)/10; -d = i% 10; - theM[0] = A * 10 +b; -N[0] = c * 10 +D; - -M[1] = A * 10 +b; +N[1] = d * 10 +C; - +M[2] = A * 10 +C; AN[2] = b * 10 +D; at -M[3] = A * 10 +C; -N[3] = d * 10 +b; - -M[4] = A * 10 +D; -N[4] = b * 10 +C; in -M[5] = A * 10 +D; toN[5] = c * 10 +b; + -M[6] = b * 10 +A; theN[6] = c * 10 +D; * $M[7] = b * 10 +A;Panax NotoginsengN[7] = d * 10 +C; - theM[8] = b * 10 +C; +N[8] = d * 10 +A; A theM[9] = b * 10 +D; +N[9] = c * 10 +A; - $M[10] = c * 10 +A; $N[10] = d * 10 +b; - -M[11] = c * 10 +b; theN[11] = d * 10 +A; - for(intj = 0; J < 12; J + +) {Wuyi if(i = = m[j] *N[j]) { theSYSTEM.OUT.PRINTLN (i + "=" + M[j] + "*" +n[j]); - } Wu } - About } $ } -}
Output
1 1260 =2 1395 =3 * 1435 = 5 *4 1530 = =6 2187 =7 6880 =8 6880 = 80 * 86
Java:thinging in Java p154 exercise