查找4位数的所有吸血鬼数字以及创建斐波那契数列

4位数中的所有吸血鬼数字

  public int findCriDatas()
    {
        int index = 0;
        int result = 0;
        int[] datas = new int[4];		
        int[] resultdatas = new int[4];
        for (int i = 10; i < 100 ; i++)
        {
            for (int j = i;j< 100;j++)
            {
                result = i *j;
                if (result > 999 && result <10000)
                {
                    datas[0] = i/10;;datas[1] = i%10;datas[2] = j/10;datas[3] = j%10;

                    resultdatas[0] = result/1000; resultdatas[1] = (result/100)%10;
                    resultdatas[2] = (result%100)/10; resultdatas[3] = (result%10);

                   Arrays.sort(datas);
                   Arrays.sort(resultdatas);
                   if (Arrays.equals(datas,resultdatas))
                   {
                       System.out.println(""+ i +"*" + j + "=" + result);
                        index ++;
                   }
                }

            }
        }
        return index;
    }

以下创建斐波那契数列函数中,参数为需要创建数列的个数

   public int[] createDatas(int count)
    {
        int[] result = new int[count];
        for (int i= 0; i <count;i++)
        {
            if (i == 0 || i == 1)
                result[i] = 1;
            else
            {
                result[i] = result[i-1] + result[i-2];
            }
        }
        return result;
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值