Becasue there is a big difference between 7 and '7'
The first is a number, the second is a character.
A
string
is made up of a sequence of characters, so 777 as a string is "777": three characters '7' following each other.
A character can contain '7', but it can also contain 'H', 'E', 'L', 'L', or 'O' - so trying to compare it to a numeric value only works if you use the value for the character in a right character set.
And so x[2] is a single character '7' which is not the same value as 7 the number.
Try this:
if (x[2] == '7')
and it'll work.