如果用户对“Continue?:( y / n)”提示符回答是,我试图让我的代码循环提示输入矩形长度和宽度。
目前正在循环“继续?:(y / n)”部分而不是“输入长度:”和“输入宽度:”< / em>部分。 任何帮助表示赞赏!
import java.util.Scanner;
public class Day1 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Welcome to Grand Circus' Room Detail Generator!");
double length = 0.0;
double width = 0.0;
double area = 0.0;
double perimeter = 0.0;
System.out.println("Enter Length: ");
length = scanner.nextInt();
System.out.println("Enter Width: ");
width = scanner.nextInt();
area = length * width;
perimeter = 2 * (length + width);
System.out.println("Area: " + area);
System.out.println("Perimeter: " + perimeter);
Scanner sc = new Scanner(System.in);
String response;
do {
System.out.print("Continue? (y/n):");
response = sc.next();
} while (response.equals("y") || response.equals("Y"));
}
}
答案 0 :(得分:3)
放
Scanner sc = new Scanner(System.in);
String response;
do {
前
System.out.println("Enter Length: ");
为什么循环体外的任何内容(do {
和} while (...)
之间的内容)会重复?