找出4位数的所有吸血鬼数字

public class VampireNumbers { 
  static int a(int i) {
   return i/1000;
  }
  static int b(int i) {
   return (i%1000)/100;
  }
  static int c(int i) {
   return ((i%1000)%100)/10;
  }
  static int d(int i) {
   return ((i%1000)%100)%10;
  }
  static int com(int i, int j) {
   return (i * 10) + j;
  }
  static void productTest (int i, int m, int n) {
   if(m * n == i) System.out.println(i + " = " + m + " * " + n);
  } 
 public static void main(String[] args) {  
  for(int i = 1001; i < 9999; i++) {   
   productTest(i, com(a(i), b(i)), com(c(i), d(i)));
   productTest(i, com(a(i), b(i)), com(d(i), c(i)));
   productTest(i, com(a(i), c(i)), com(b(i), d(i)));
   productTest(i, com(a(i), c(i)), com(d(i), b(i)));
   productTest(i, com(a(i), d(i)), com(b(i), c(i)));
   productTest(i, com(a(i), d(i)), com(c(i), b(i)));
   productTest(i, com(b(i), a(i)), com(c(i), d(i)));
   productTest(i, com(b(i), a(i)), com(d(i), c(i)));
   productTest(i, com(b(i), c(i)), com(d(i), a(i)));
   productTest(i, com(b(i), d(i)), com(c(i), a(i)));
   productTest(i, com(c(i), a(i)), com(d(i), b(i)));
   productTest(i, com(c(i), b(i)), com(d(i), a(i)));
  }   
 } 
}



版权声明:本文为axl1988713原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。