/**
* 问题:
* 一个整数,它加上100后是一个完全平方数,
* 加上168又是一个完全平方数,请问该数是
* 多少?
*
*
* 程序分析:利用Math.floor(double a)方法
* 的作用。
*
* @author Administrator
*
* 程序如下:
*
*/
public class PerfectSquare {
public static void main(String args[]){
for(long i=0;i<100001;i++){
/*Math.floor(double a)方法的作用:
* 返回最大的(最接近正无穷大)double值,该值
* 小于或者等于参数,并且等于某个整数。
*/
if(Math.floor(Math.sqrt(i+100))==Math.sqrt(i+100)&&Math.floor(Math.sqrt(i+168))==Math.sqrt(i+168)){
System.out.println(i);
}
}
}
}
运行结果如下:
run:
156
成功生成(总时间:0 秒)