9位优美乘积式

import java.util.Scanner;

public class Testa {

public static void main(String[] args) {
	/*
	System.out.println("请输入n:(代表求多少个连续的合数)");
	Scanner reader=new Scanner(System.in);
	int n=reader.nextInt();
	*/
	int total=0;
	for(int i=10;i<=987;i++){
		for(int j=i+1;j<=9876;j++){
			if(i<j){
				boolean a=f(i);
				if(a){
					boolean b=f(j);
					if(b){
						boolean ok=ff(i,j);
						if(ok){
							total++;
							System.out.println(i+"*"+j+"="+(i*j));
						}
					}
				}
			}
			
		}
	}
	System.out.println(total);
 }	
	

//去重
public static boolean f(int n){
	String result=String.valueOf(n);
	
	int length=result.length();
	
	for(int i=0;i<length-1;i++){
		for(int j=i+1;j<length;j++){
		
			char a=result.charAt(i);
			char b=result.charAt(j);
			if(a==b||a=='0'||b=='0'){
				
				return false;
			}
			
		}
	}
	
	return true;
	
}
//判断是否符合条件
public static boolean ff(int a,int b){
	int x[]=new int[10];
	for(int i=0;i<10;i++){
		x[i]=0;
	}
	
	int min=a;
	int max=b;
	
	int c=min*max;
	
	if(c>9876||c<1000){
		return false;
	}
   
	boolean ok=f(c);
	if(ok){
	//对第一个数
     int temp=min;
     int temp2=temp%10;
     x[temp2]=x[temp2]+1;
     temp=temp/10;
     while(temp>=10){
    	 temp2=temp%10;
	     x[temp2]=x[temp2]+1;
	     temp=temp/10;
     }
     x[temp]=x[temp]+1;
     
     //对第二个数
      temp=max;
     temp2=temp%10;
     x[temp2]=x[temp2]+1;
     temp=temp/10;
     while(temp>=10){
    	 temp2=temp%10;
	     x[temp2]=x[temp2]+1;
	     temp=temp/10;
     }
     x[temp]=x[temp]+1;
     
     //对第三个数
     temp=c;
     temp2=temp%10;
     x[temp2]=x[temp2]+1;
     temp=temp/10;
     while(temp>=10){
    	 temp2=temp%10;
	     x[temp2]=x[temp2]+1;
	     temp=temp/10;
     }
     x[temp]=x[temp]+1;
     
	for(int i=1;i<10;i++){
	
	   if(x[i]!=1){
		 
		  return false;
	   }
	  
	  
	}
	}
	else{
		return false;
	}
	return true;
	
}

}

转载于:https://my.oschina.net/u/2511906/blog/848652

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值