나는 상태가 참일 때 루프가 계속 실행된다는 것을 알고 있습니다. 나는 단순히 loop = false로 타이핑 한 후 루프를위한} 괄호 뒤에 코딩을 계속할 수 있다고 생각했다. 분명히 내가 틀렸어. 아무 것도하지 않을거야. 누군가는이 반복문에서 빠져 나오는 법을 보여주십시오.이 괴물 같은 루프를 벗어나는 방법
System.out.println("You total balance is 0.00, "
+ "please deposit coins and type done when finished");
while(loop){
if (input.hasNextInt()){
deposit = input.nextBigDecimal();}
String change = input.next();
switch (change){
case "quarter":
balance= quarter.multiply(deposit);
total=total.add(balance);
System.out.println("Your balance is "+ total +" :Make addiontal deposit(s)");
break;
case "dime":
balance=dime.multiply(deposit);
total=total.add(balance);
System.out.println("Your balance is "+ total +" :Make addiontal deposit(s)");
break;
case "nickel":
balance=nickel.multiply(deposit);
total=total.add(balance);
System.out.println("Your balance is "+ total +" :Make addiontal deposit(s)");
break;
case "penny":
balance=penny.multiply(deposit);
total=total.add(balance);
System.out.println("Your balance is "+ total +" :Make addiontal deposit(s)");
break;
case"done":
System.out.println("Your total is $"+total);
fee=total.multiply(feeRate);
System.out.println("The exchance fee is 9.1% which amounts to $"+fee);
grandTotal=total.subtract(fee);
System.out.println("Your total balance minus the exchange fee is $"+grandTotal);
break;
default: System.out.println("There is a issue at "+change);}
} System.out.println("4");
}
}
, 실행은 중단 상태까지 루프에 남아 충족되었습니다. 루프 변수 **는 루프 내에서 ** 반드시 ** 루프 이후에 ** 설정해야합니다. – pasty