mercredi 10 octobre 2018

Not able to perform string equality

I am writing a program about echange transactions between different currencies. At a certain point in the program asks the user to input the initial currency and check if the inputed string is within the values specified by the program:

while (!isSet) { System.out.println("Give the Initial Currency : USD | EUR | GBP | JPY | CHF | CAD | AUD"); start_currency = scanner2.nextLine();

if ((start_currency != "USD") && (start_currency != "EUR") && (start_currency != "GBP") && 
        (start_currency != "JPY") && (start_currency != "CHF") && (start_currency != "CAD") && (start_currency != "AUD"))
{
    System.out.println("Please choose a value from the initial currencies specified above!");
        }
    else
        isSet = true;
}

The program passes through this block of code without being able to execute it (as if the condition is always false.

Can anyone pinpoint my error in the aforementioned part of the code?

Kind regards, Lampros

Aucun commentaire:

Enregistrer un commentaire