2014-12-26 3 views
-1
double Euro = 1.37; 
    double USAD = 1.81; 
    double JapYen = 190.00; 
    double Zloty = 5.88; 

    //First menu choice screen 
    if (MenuChoice == 1) 
    { 
    System.out.println("Which of the following currencies do you wish to exchange into sterling?"); 
    System.out.println("Euro - EUR"); 
    System.out.println("USA Dollar - USD"); 
    System.out.println("Japanese Yen - JPY"); 
    System.out.println("Polish Zloty - PLN"); 
    System.out.println("Please enter the three letter currency: "); 
    String CurChoice = keybStr.next(); 

이것이 내가 얻은 것입니다. 3 글자 통화를 입력 할 수 있도록 다음 코드를 확인합니다. 어떤 도움이 필요합니까? 사용자 입력은 CurChoice 변수에 저장되고 나중에 코드에서 사용됩니다.3 글자 입력의 확인에 대해 확실하지 않음

답변

1

시도 뭔가 같은 :

String CurChoice = ""; 
boolean isCorrectCurrency = false; 
do { 
    CurChoice = keybStr.next(); 
    isCorrectCurrency = CurChoice.matches("^EUR|USD|JPY|PLN$"); 
    if (isCorrectCurrency) { 
     System.out.println("Hey It matched to proper currency"); 
    } else { 
     System.out.println("Hey It didn't matched to proper currency. Please retry"); 
    } 
} while (!isCorrectCurrency); 
관련 문제