while 문이 작동하지 않는 이유를 알아낼 수 있습니까? 루프는 i = 3 후에 멈추지 만 continueSurvey = 0이면 멈추지 않습니다. continueSurvey를 O로 변경하면 루프가 종료되지 않습니다. 프로세스로 들어가도 변수가 있음을 알 수 있습니다. 0이면 루프가 계속됩니다. 당신은 사용자가 계속하고자하는 경우 요청While 루프를 여러 조건으로 사용하는 경우
import java.util.Scanner;
public class SurveyConductor
{
public static void main(String[] args)
{
Survey a = new Survey();
a.display();
a.enterQuestions();
int continueSurvey = 1;
int i = 0;
while ((continueSurvey != 0) && (i < 3))
{
for (int row = a.getRespID(); row < 3; row++)
{
System.out.println("Respondent " + (row+1) + " Please tell us how you would rate our: ");
for (int col = 0; col < 3; col++)
{
Scanner input = new Scanner(System.in);
System.out.println(a.presentQuestion(col) + ": ");
System.out.println("Enter your response (1-Strongly Disagree, 2-Disagree, 3-Neutral, 4-Agree, 5-Strongly Agree): ");
int response = input.nextInt();
if ((response < 1) || (response >5))
{
while ((response < 1) || (response > 5))
{
System.out.println("Your response must be between 1 and 5. Please try again.");
System.out.println(a.presentQuestion(col) + ": ");
System.out.println("Enter your response (1-Strongly Disagree, 2-Disagree, 3-Neutral, 4-Agree, 5-Strongly Agree): ");
response = input.nextInt();
}
}
a.logResponse(row,col,response);
System.out.println();
}
a.displaySurveyResults();
System.out.println();
System.out.println("The top rated question is Question #" + a.topRatedQuestion() + ".");
System.out.println("The bottom rated question is Question #" + a.bottomRatedQuestion() + ".");
System.out.println();
Scanner input2 = new Scanner(System.in);
System.out.println("Are there any more repondents (0 - No, 1 - Yes): ");
continueSurvey = input2.nextInt();
a.generateRespondentID();
i++;
}
}
}
}
감사합니다. 나는 내 코드에 break 문을 넣는 것을 끝내었다. 나는 for 루프 밖에서 질문을 움직이려고 시도했지만 다음 응답자가 생성되기 전에 질문을 할 필요가있었습니다. –
@MichelleAnderson 그래, 그게 아마도 가장 의미가 솔루션입니다 :) StormeHawke의 대답을 받아 들일 그것은 비슷한 문제가있을 수 있습니다 다른 사람들을 도울 것입니다. – Jordan