当前位置: 代码迷 >> 综合 >> 计蒜客 x的平方根
  详细解决方案

计蒜客 x的平方根

热度:94   发布时间:2024-01-19 22:55:36.0


设计函数int sqrt(int x),计算 xxx 的平方根。
输入格式

输入一个 整数 xxx,输出它的平方根。直到碰到文件结束符(EOF)为止。
输出格式

对于每组输入,输出一行一个整数,表示输入整数的平方根。
样例输入

1
2
3
4
5
6
7
8
9

样例输出

1
1
1
2
2
2
2
2
3



import java.util.Scanner;public class Main {public static void main(String[] args) {Scanner sc = new Scanner(System.in);int x;long an;while(sc.hasNext()) {x=sc.nextInt();an=fun(x);System.out.println(an);}}private static int fun(int x) {double a = Math.sqrt(x);int b = (int)a;return b;}}

  相关解决方案