-1

Im writing a class for a card that takes in two string parameters,

When I check the string if it's an "a" it throws the NumberFormatException error.

Card(String s, String  f) 
{
    suit = s;
    if(f == "a")
    {
        value = 11;
    }

    else if (f == "j" || f == "k" || f == "q")
    {
        value = 10;
    }

    else
    {
        value = Integer.parseInt(f);
    }
    face  = f; 
}

1 Answers1

0

You can't compare strings with ==. That only compares the "shallow" reference values of the two strings, whether if they point to the same string object (most). You have to use the .equals function of the string to check equality with strings.

theKidOfArcrania
  • 488
  • 4
  • 13