奇妙的数字

小明发现了一个奇妙的数字。它的平方和立方正好把0~910个数字每个用且只用了一次。

你能猜出这个数字是多少吗?

 

请填写该数字,不要填写任何多余的内容。


分析:

求出平方和,立方和,然后判断是否包含0~9

判断0~9不重复的思路为,利用for循环和 indexof 返回0~9的下标,因为用了0~9每一个数字,这是一个10位数,并且每个下表都会>=0


public class a3 {

  public a3(){

扫描二维码关注公众号,回复: 2549444 查看本文章

       String a = null;

       String b= null;

        String c = null;

       for (int i = 0; i < 500; i++) {

              a = String.valueOf((int)Math.pow(i, 2));

              b = String .valueOf((int)Math.pow(i, 3));

              c = a + b;

 

              if (c.length()==10) {


                     int abc= 0;

                     for (int j = 0; j <= 9; j++) {

                            if(c.indexOf(String.valueOf(j))>=0){

                                   abc++;


                            }

                     }

                     if (abc==10) {

                            System.out.println(i);

                     }

       }

       }

}

public static void main(String[] args) {

// TODO Auto-generated method stub

       new a3();

 

}

 

}




猜你喜欢

转载自blog.csdn.net/qq_38930784/article/details/78822124