三行代码搞定,一定要熟用工具类啊哥哥们
求平方根
http://www.nowcoder.com/questionTerminal/09fbfb16140b40499951f55113f2166c
思路:
熟悉工具类的都知道,Math里面有个floor就是向下取整的而且参数为double类型,而int转double是没问题的,然后向下取整后,double类型强转回int也不会有精度缺失了。。。
public int sqrt (int x) { // write code here double temp = Math.sqrt(x); int res = (int)Math.floor(temp); return res; }
阿巴阿巴阿巴