2016-03-29 24 views
0

「続行:(y/n)」プロンプトに対して、ユーザーが「はい」と答えた場合、長方形と長さを入力するプロンプトをループさせようとしています。do whileループは、私が望むように動作させるにはどうすればいいですか?

それが現在"?続行:(Y/N)" をループしている一部ではない"を入力してください長さ:":一部とは "幅を入力します"。 ご協力いただければ幸いです!

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")); 
    } 
} 

答えて

3

System.out.println("Enter Length: "); 

Scanner sc = new Scanner(System.in); 
String response; 
do { 

を入れて、なぜあなたのループ本体(do {} while (...)間のもの)の外に何が繰り返されるのでしょうか?

+0

ありがとうございました。私が必要なのはこれだけです。 – jcdee

関連する問題