吸血鬼数字的实现(thinking in java练习题)

/**
 吸血鬼数字是指位数为偶数的数字,可以由一对数字相乘而得,而这对数字
 各包含乘积的一半位数的数字,其中从最初的数字中选取的数字可以任意排序。
 以两个0结尾的数字是不允许的。
 例如,下面数字都是吸血鬼数字:
 1260 = 21 * 60
 1827 = 21 * 87
 2187 = 27 * 81
 写一个程序,找出4位数的所有吸血鬼数字。
**/
public class Test_05{
	public static void main(String[] args){
		check();
	}
	public static void check(){
		for(int i = 1000; i < 10000; i++){
			if(i %100 == 0) continue;
			int o = i%10;			//one
			int t = i/10%10;		//ten
			int h = i/100%10;	//hundrod
			int th = i/1000;	//thound
			//System.out.println("i = " + i + " = " + thound + hundrod + ten + one);
			if(i == (th * 10 + h) * (t * 10 + o)){
				System.out.println(i + " = " + th + h + " * " + t + o);
			}
			if(th != h && i == (h * 10 + th) * (t * 10 + o)){
				System.out.println(i + " = " + h + th + " * " + t + o);
			}
			if(o != t && i == (th * 10 + h) * (o * 10 + t)){
				System.out.println(i + " = " + th + h + " * " + o + t);
			}
			if(th != h && o != t && i == (h * 10 + th) * (o * 10 + t)){
				System.out.println(i + " = " + h + th + " * " + o + t);
			}
			
			if(t != h){
				if(i == (th * 10 + t) * (h * 10 + o)){
					System.out.println(i + " = " + th + t + " * " + h + o);
				}
				if(th != t && i == (t * 10 + th) * (h * 10 + o)){
					System.out.println(i + " = " + t + th + " * " + h + o);
				}
				if(o != h && i == (th * 10 + t) * (o * 10 + h)){
					System.out.println(i + " = " + th + t + " * " + o + h);
				}
				if(th != t && o != h && i == (t * 10 + th) * (o * 10 + h)){
					System.out.println(i + " = " + t + th + " * " + o + h);
				}
			}
			
			if(o != h){
				if(i == (th * 10 + o) * (h * 10 + t)){
					System.out.println(i + " = " + th + o + " * " + h + t);
				}
				if(th != o && i == (o * 10 + th) * (h * 10 + t)){
					System.out.println(i + " = " + o + th + " * " + h + t);
				}
				if(h != t && i == (th * 10 + o) * (t * 10 + h)){
					System.out.println(i + " = " + th + o + " * " + t + h);
				}
				if(th != o && h != t && i == (o * 10 + th) * (t * 10 + h)){
					System.out.println(i + " = " + o + th + " * " + t + h);
				}
			}
		}
	}
}
// 1234: 12 * 34 || 21 * 34 || 12 * 43 || 21 * 43
// 1234: 13 * 24 || 31 * 24 || 13 * 42 || 31 * 42
// 1234: 14 * 23 || 41 * 23 || 14 * 32 || 41 * 32 

你可能感兴趣的:(java,String,Class)