- class shuixian {
- public static void main(String args[])
- {
-
-
- long startTime = System.nanoTime();
- fa1();
- long Time = System.nanoTime() - startTime;
-
- long startTime1 = System.nanoTime();
- fa2();
- long Time1 = System.nanoTime() - startTime1;
-
- long startTime2 = System.nanoTime();
- fa3();
- long Time2 = System.nanoTime() - startTime2;
- System.out.println("三"+Time2+"\n"+
- "一"+Time+"\n"+
- "二"+Time1);
- }
-
-
- public static void fa2(){
- for(int i=100;i<1000;i++)
- {
- int a =i%10; //个位
- int b = (i/10)%10; //十位
- int c =(i/100)%10; //百位
-
- if(Math.pow(a,3)+Math.pow(b,3)+Math.pow(c,3)==i)
- System.out.println(i);
- }
-
- }
- public static void fa1(){
- for(int i=1;i<10;i++)
- {
- for(int j=0;j<10;j++)
- {
- for(int k=0;k<10;k++)
- {
-
- if(Math.pow(i,3)+Math.pow(j,3)+Math.pow(k,3)==i*100+j*10+k)
- System.out.println(i+""+j+""+k);
- }
- }
- }
- }
- public static void fa3(){
- int n= 100;
- for(int i=0;i<900;i++)
- {
- String ar=(n++)+"";
- Integer a = new Integer(ar.substring(0,1));
- Integer b = new Integer(ar.substring(1,2));
- Integer c = new Integer(ar.substring(2,3));
- if(Math.pow(a,3)+Math.pow(b,3)+Math.pow(c,3)==a*100+b*10+c)
- System.out.println(n);
- }
- }
- }
复制代码 |
|