首页 > 学院 > 开发设计 > 正文

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

2019-11-17 04:04:32
字体:
来源:转载
供稿:网友
view plaincopy to clipboardPRint?
/**  
* 找出四位数所有的吸血鬼数字  
* 吸血鬼数字:位数为偶数的数字可以由一对数字相乘而得,这对数字包含乘积一半的位数  
* 如:1260 = 21*60  
*/  
public class Vampire {   
    /**  
     * @param args  
     */  
    public static void main(String[] args) {   
        // TODO Auto-generated method stub   
           
        String s="";   
        for(int i=1; i<10; i++){   
            for(int j=0; j<10; j++){   
                s += (10*i+j)+" ";   
            }   
        }   
        System.out.println(s);   
           
        String[] arr = s.split(" ");   
        System.out.println("两位数的个数为:"+arr.length);   
           
        int a,b;   
        int count=0;           
        for(int j=0; j<arr.length; j++){   
            for(int k=0; k<arr.length; k++){                
                a = Integer.valueOf(arr[j]).intValue();   
                b = Integer.valueOf(arr[k]).intValue();   
                //为能以两个0结尾   
                if(a*b<10000 && a*b>1000 && (a*b)%100!=0){   
                    count++;   
                    System.out.print(arr[j]+"_"+arr[k]+" ");   
                }                      
            }   
            System.out.println();   
        }   
        System.out.println("the total number is "+count);   //6370   
               
    }   
}   
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表