已知: x!+y!+z!=xyz 如:1!+4!+5!=145如何用java程序编写,求助

解决方案 »

  1.   

    这个很简单,你可以看一下:
    import java.util.Scanner;
    public class FacSx 
    {
    public static void main(String args[])
    {
    System.out.println("输入第一个数i:");
    Scanner s1=new Scanner(System.in);
    int i=s1.nextInt();
    System.out.println("输入第二个数j:" );
    Scanner s2= new Scanner(System.in);
    int j=s2.nextInt();
    System.out.println("输入第三个数k:" );
    Scanner s3= new Scanner(System.in);
    int k=s3.nextInt();
    int m=fac(i)+fac(j)+fac(k);     //求和System.out.println("The sum is :"+m );
    }
    public static int fac(int n ) //递归法求阶乘,

    if (n ==0 ) 
    return 0;
    else if(n==1)
    return 1;
    else 
    return n*fac(n-1); 
    }
      

  2.   

    我不知道你具体要求出x,y,z在多少之内  你需要的话自己改循环次数就好
    public static void main(String[] args) {
    for(int x=1;x<=100;x++){
    for(int y=1;y<=100;y++){
    for(int z=1;z<=100;z++){
    if((x*100+y*10+z) == (fun(x)+fun(y)+fun(z)))
    System.out.println(x+"---"+y+"-----"+z);
    }
    }
    }
    }
    public static int fun(int i){
    if(i==1)
    return 1;
    return i*fun(i-1); 
    }
      

  3.   


    import java.util.Scanner;
    public class FactorialAndSum1126
    {
    public static void main(String[] args)
    {
    System.out.println("请输入范围:(<9999999)");
    Scanner scan=new Scanner(System.in);
    int number=scan.nextInt();
    int total=0;
    //把0,9的阶乘放入数组。
    //
    int[] ten=new int[10]; //分别放0,9阶乘。
    ten[0]=1; //0!=1.
    for(int i=1;i<ten.length;i++)
    {
    ten[i]=ten[i-1]*i;
    }
    //循环计算1--number
    //
    for(int i=1;i<number;i++)
    {
    int[] ii=getIntArrays(i);
    total=0;
    for(int k=0;k<ii.length;k++)
    {
    total+=ten[ii[k]];
    }
    if(i==total)
    {
    for(int n=0;n<ii.length;n++)
    {
    System.out.print(ii[n]+"!"+"+");
    }
    System.out.println("\b = "+total);
    }
    }
    }
    //把一个数的各位放入一个数组。比如1023,返回[1,0,2,3]
    public static int[] getIntArrays(int m)
    {
    String s=""+m; //通过字符串的方法,取得位数。比如,1023 是4位。
    int length=s.length();
    int[] end=new int[length]; //定义一个这样长的数组。 int i=0;
    while(m>0)
    {
    end[length-i-1]=m%10; //低位在数组后边。
    m=m/10;
    i++;
    }
    return end;
    }
    }
    /*
    请输入范围:(<9999999)
    9999999
    1! = 1
    2! = 2
    1!+4!+5! = 145
    4!+0!+5!+8!+5! = 40585
    */