本帖最后由 MengXuer 于 2009-08-14 16:56:50 编辑

解决方案 »

  1.   


    public class Test
    {
    public static void main(String... args) {
    for(int i = 0; i < 10000;i++) {
    int a = i + 100;
    int b = a + 168;
    if(((int)Math.sqrt(a))==((int)Math.ceil(Math.sqrt(a)))&&
    ((int)Math.sqrt(b))==((int)Math.ceil(Math.sqrt(b)))) {
    System.out.println(i);
    }
    }
    }
    }
    21
    261
    1581
      

  2.   

    public class mathtest {
        public static void main(String args[]){
            double x;
            double y;
            int i;
            //System.out.print(Math.sqrt(100));
            for (i=1;i<10000;i++){
                x=Math.sqrt(i+100);
                y=Math.sqrt(i+168);
                //System.out.println(i);
                if((x-(int)x)<1e-7 && (y-(int)y)<1e-7){
                    System.out.println(i);
                }
            }
        }}F:\java>java mathtest
    156
      

  3.   

    哦,那样的话,你和答案一样了. public class mathtest {
        public static void main(String args[]){
            double x;
            double y;
            int i;
            //System.out.print(Math.sqrt(100));
            for (i=1;i<10000;i++){
                x=Math.sqrt(i+100);
                y=Math.sqrt(i+268);
                //System.out.println(i);
                if((x-(long)x)<1e-7 && (y-(long)y)<1e-7){
                    System.out.println(i);
                }
            }
        }}F:\java>java mathtest
    21
    261
    1581