当前位置:编程学习 > JAVA >>

java求吸血鬼数字算法

import java.util.*; 
public class XiXueGui { 
     public static void main(String []args) throws Exception 
      {     
       ArrayList<Integer> list=new ArrayList<Integer>(); //提高效率所引用线性表  
       ArrayList<Integer> result=new ArrayList<Integer>(); //防止结果集重复  
         boolean test=true ;   
         boolean flag=false ; 
        for(int i=11;i<99;i++) 
          for(int j=(1000/i)+1;j<99;j++)   
             {  
               list.clear() ; 
               String str1=new Integer(i*j).toString() ;   //相乘后  
               String str2=String.valueOf(i)+String.valueOf(j);     
               for(int m=0;m<4;m++) 
               {   
                   for(int n=0;n<4;n++) 
                   {   
                       test=true ; 
                       for(int x=0;x<list.size();x++) 
                           if(n==list.get(x)) test=false ;  //如果表中存在索引  
                       if(test==false) 
                           continue ; 
                       if(str1.charAt(m)==str2.charAt(n)) 
                       { 
                           list.add(n) ;    
                           break ; 
                       } 
                   }                
               }       
               if(list.size()==4) 
               {  flag=true ; 
                   for(int count=0;count<result.size();count++) 
                   { 
                       if(result.get(count)==i*j){ 
                           flag= false ; 
                       }                            
                   } 
                   if(flag!=false) 
                   { 
                       System.out.println(i*j+"="+i+"*"+j); 
                       result.add(i*j) ; 
                   }            
               } 
             }       
       } 

 

 

摘自 yue7603835的专栏

补充:软件开发 , Java ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,