public static double getSqrt(){
System.out.println("请输入:");
Scanner scanner = new Scanner(System.in);
//1
// int n;
// do{
// n = scanner.nextInt();
// }while (!(n < 10000));
// return Math.sqrt(n);
//2
// int n = scanner.nextInt();
// while (!(n < 1000)){
// n = scanner.nextInt();
// }
// return Math.sqrt(n);
//3.
while(true){
int n = scanner.nextInt();
if(n <1000 && n>=0) {
System.out.println(Math.sqrt(n));
} else {
System.out.println("请重新输入");
}
}
}
public static void main(String[] args) {
getSqrt();
}}
从键盘输入1000以内正整数,输出其平方根
猜你喜欢
转载自blog.csdn.net/weixin_44827160/article/details/88783204
今日推荐
周排行