나는 루프를 전환하는 새로운 오전 만들고이 통화 변환기 프로그램에 여러 가지 문제가 있습니다. 먼저, 사용자가 -1을 입력 할 때까지 계속 값을 입력하는 사례 1을 반복하여 루프를 중지하고 계속 이동하려고합니다. 현재로서는 그렇게하지 않습니다. 스위치 1에 GPR 값을 입력하고 원래 GPR 값을 저장 한 상태로 메뉴로 되돌아갑니다.입니까? while 루프? 환율 계산기 프로그램 java
코드는 여기에 있습니다 :
import java.util.Scanner;
public class Conversion {
public static void main(String[] args) {
double pound;
double euro;
double dollars;
double yen;
double rupees;
double poundEuro;
double poundDollars;
double poundYen;
double poundRupees;
int Choice;
Scanner input = new Scanner(System.in);
Scanner exchange = new Scanner(System.in);
System.out.println("Please choose an option:");
System.out.println("1. Enter values and type -1 to stop");
System.out.println("2. Euros (1GBP = 1.28EUR)");
System.out.println("3. Dollars (1GBP = 1.51USD)");
System.out.println("4. Yen (1GBP = 179.80JPY)");
System.out.println("5. Rupees (1GBP = 95.60INR)");
System.out.println("6. Exit");
Choice = input.nextInt();
switch (Choice) {
case 1:
while (!exchange.equals("-1"));{
pound = exchange.nextDouble();
System.out.print("Please enter your values you would like to exchange (Type '-1' to stop) ");
}
case 2:
pound = exchange.nextDouble();
dollars = 1.51;
poundDollars = pound * dollars;
System.out.println("Your amounts in euros are" + poundDollars);
case 3:
pound = exchange.nextDouble();
yen = 1.28;
poundYen = pound * yen;
System.out.println("Your amounts in euros are" + poundYen);
case 4:
pound = exchange.nextDouble();
rupees = 1.28;
poundRupees = pound * rupees;
System.out.println("Your amounts in euros are" + poundRupees);
case 5:
pound = exchange.nextDouble();
euro = 1.28;
poundEuro = pound * euro;
System.out.println("Your amounts in euros are" + poundEuro);
case 6:
break;
}
input.close();
exchange.close();
}
}
'switch' 문은 루프 수 없습니다. – immibis
''나는 루프를 바꾸는 것이 새롭다. '- 나는 그렇다. 사실 나는 그런 짐승에 대해 들어 본 적이 없다. while 루프와 같은 실제 루프 구조를 사용하는 것이 좋습니다. 튜토리얼이 도움이 될 것입니다. –
아니요, 아니요, 'swich'루프, 'switch'루프가 아닙니다. –