-5
사용자에게 입력을 요청하고 모든 사례의 모든 내용을 읽은 다음 output.displayMainMenu();
에 다시 루프하여 4를 입력 할 때까지 반복합니다. 프로그램을 종료하십시오.자바 프로그래밍이 while 문을 루프로 가져오다
output.displayMainMenu();
int entry = keyboard.nextInt();
while(entry >= 1 || entry <=4) {
output.displayMainMenu();
switch(entry) {
case 1:
output.displayStockChoices(portfolio);
portfolio.editPostion();
portfolio.displayPositions();
break;
case 2:
portfolio.updateCurrentPrice();
break;
case 3:
System.out.print(investor.toString() + "Account Balance: " +portfolio.calcTotalAccountValue());
break;
case 4:
System.out.print("Done.");
break;
default:
System.out.print("please enter 1-4!");
}
break;
}
여기 엔 무한 루프가있을 것입니다. 왜냐하면'entry'는 결코 루프에서 재 할당되지 않기 때문입니다. – Makoto
|| 논리 OR이므로 두 조건 중 하나가 항상 참입니다. &&는 논리적 AND이며 찾고있는 것입니다. –
스위치 외부에 '휴식;'이 있습니다. 이것은 루프에서 벗어납니다. 하지만 while 루프 조건과 사용자 입력을 얻는 것과 같은 몇 가지 문제가 있습니다. – AntonH