-4

I am trying to convert the tenth digit of an array to a number (10) if it is the value 'x'. I have tried...

if (array[9] === 'x') {
'x' === 10;
};

Thanks

2 Answers2

3

Try this, assuming that array is a char[]:

if (array[9] == 'x') {
    array[9] = 10;
}

By the way, the code you posted is not valid for Java. This is not an operator: ===, we must use = for assignment and the trailing ; after the last } is unnecessary.

Óscar López
  • 232,561
  • 37
  • 312
  • 386
  • 2
    I don't know what OP wants but you might want to point out that `array[9] = 10` will assign the value of `(char)10` to that element and that `(char)10` is a whitespace character. – PakkuDon Feb 13 '14 at 00:26
0

I edited your code already.

 if (array[9] == 'x') //Line 1
 {
     array[9] = 10; // Line 2
 }

On Line 1 you said ===. Java uses == to check if two primitive values are equal in value.

On Line 2 you used three equal signs again. If you want to reassign a variable, you will need to use ONE equal sign.

ChriskOlson
  • 513
  • 1
  • 3
  • 12