0

I'm trying to use switch. It works for all the cases except for one which has absolutely no difference with the others.

It tests the remaining from the division by 13 of the first array(int) and depending on that assigns specific values to the second one(Char).

 public static char[] FindValue(int[] OCards) {
    char[] OValue = new char[5];
    int n;
    for (int i = 0; i < 5; i++) {
        n = OCards[i] % 13;
        switch (n) {
            case 0:
                OValue[i] = 'A';
                break;
            case 1:
                OValue[i] = '2';
                break;
            case 2:
                OValue[i] = '3';
                break;
            case 3:
                OValue[i] = '4';
                break;
            case 4:
                OValue[i] = '5';
                break;
            case 5:
                OValue[i] = '6';
                break;
            case 6:
                OValue[i] = '7';
                break;
            case 7:
                OValue[i] = '8';
                break;
            case 8:
                OValue[i] = '9';
                break;
            case 9:
                OValue[i] = '10'; //Error here 'unclosed character literal'
                break;
            case 10:
                OValue[i] = 'V';
                break;
            case 11:
                OValue[i] = 'D';
                break;
            case 12:
                OValue[i] = 'R';
                break;


        }
    }
    return OValue;
}
3
  • A character literal can only contain exactly 1 character. 10 are two characters. Commented Dec 8, 2014 at 0:20
  • Can a character literal be more than one character? Commented Dec 8, 2014 at 0:20
  • How is 10 a single character?? Commented Dec 8, 2014 at 0:21

4 Answers 4

3

As others have noted, the problem is that '10' isn't a character.

We can solve this, and at the same time save your finger a lot of bending:

n = OCards[i] % 13;
OValue[i] = "A23456789TVDR".charAt(n);

That one line replaces your entire switch statement.

I'm not certain of the right symbol to use, though. In English, it would be a T. But in French, you clearly can't use D for both dame and dix.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, this helps a lot. You're right, i'll use T and if it's not good enough, i'll change T to 10 when outputting the cards.
2

Your error is because you are trying to make a char with two characters, and you can only make a char with one.

You'll want to change your array to store ints, or as it is commonly done if you need to store char's, with 'T' or 't'.

Comments

1

Ovalue is an array of chars; '10' isn't a single character.

Comments

1

How about

  case 9:
            OValue[i] = 'T'; //use T char to stand for 10
            break

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.