이 루프가 작동하는 데 도움이 필요합니다. 루프 또는 if 문을 사용하는 방법을 알지 못하기 때문일 수 있습니다. 하지만 내가 정말 결코 없기 때문에 그건 내 문제가 될 수도 있도록 루프를 사용하는 방법을 모르는 나는 그것이 10Java 루프 :이 루프가 예상대로 멈추지 않는 이유는 무엇입니까?
import java.util.Scanner;
public class Foothill {
public static void main(String args[]){
Scanner scanner = new Scanner(System.in);
int numPurchases, totalPurchased;
boolean correct;
String menu;
numPurchases = 0;
totalPurchased = 0;
correct = false;
while(!correct)
{
System.out.println("Menu:");
System.out.println(" P (Process Purchase)");
System.out.println(" S (Shut down)");
menu = scanner.nextLine();
if (menu.charAt(0)=='S' || menu.charAt(0)=='s'){
System.exit(0);
} else if (menu.charAt(0)=='P' || menu.charAt(0)=='p'){
continue;
}
System.out.println("Your choice: " + menu.charAt(0));
System.out.println("How many yougurts would you like to buy?");
numPurchases = scanner.nextInt();
totalPurchased += numPurchases;
if (totalPurchased > 0 || totalPurchased < 10){
System.out.println("you have purchased " + totalPurchased + " yogurts");
} else if (totalPurchased >= 10){
System.out.println("Congradulations you have recieve a free Yogurt");
System.out.println("Remainding yogurt credits: " + (totalPurchased-10));
}
}
}
}
후 무료로 요구르트를 수신에 올 때 만약 문을 사용하는 데 필요한 생각 거짓과 진실이
제목 사람이 익사 제안 .. –
'while (! correct)'를 확인 했습니까? –
'if (totalPurchased> 0 || totalPurchased <10) {'- 모든 숫자가 0보다 크거나 10보다 작습니다. '&&'를 원합니다. – user2357112