public static void main(String[] args) {
Scanner in = new Scanner(System.in);
while (true) {
do {
System.out.println("Please enter a non-negative number: ");
double x = in.nextDouble();
} while (x < 0);
System.out.println("Square root is " + sqrt(x));
System.out.println("Do you want to continue? (Enter Y or N): ");
String f = in.nextLine();
if (!f.equalsIgnoreCase("Y")) {
break;
}
}
}
您的
while
语句似乎位于错误的位置。试试这个:请注意,在用户输入非负数之前,系统将继续提示用户输入非负数
相关问题 更多 >
编程相关推荐