To add to what poeple are telling you; the char literal '7' is not a character, but a number, as you will see from the Java® Language Specification (=JLS); the JLS includes it as an unsigned integer type. There are many places where you can find out the number equivalents of a character; this Unicode page has '7' on. You will notice it is shown as 37 which is hexadecimal, which equates to 55 in decimal.
In the computing world characters are mapped/coded to numbers trough various encoding schemes depend on the language on hand. Java utilize the UTF-16 encoding scheme
what happens in
is called implicit type conversion let's examine it
Java is a strong typed language . Every entity in Java have to have a type.
A type is a set of permissible values and a set of permissible operations that operate on that values. That is enforced by the compiler if you use a non valid value or operation
the compiler complains and not compile your code
You have declared the variable a as type integer that means the variable a can take only integer values like ...-1,0,1... but you give it a value of type char instead.
Normally if the type on the right hand side of an assignment is not equal(more correctly compatible) to the type on the left hand side the compiler raises an error and not compile
because you're out of the type compatibility rules. That's a characteristic of all strong typed languages and even if can be seemed hard to you the prime times help much to avoid
errors that have to be raised at run time. imagine a critical situation such as an such error in an nuclear plant would be catastrofic
Now turn in us because char and int are compatible types the compiler doesn't complain instead help you in hiding your error(correctly you had to declare a of type char if you intend
to assign it a character such as '7') in transform your character '7' in an integer that corresponds in an int i.e. 55 on the UTF-16 conversion table
[Arguing with an engineer is a lot like wrestling in the mud with a pig. After a few hours, you realize that he likes it] [Learn code first? no we apply to learn programming(or also)first thanks]
Every time you till, you lose 30% of your organic matter. But this tiny ad is durable:
Free, earth friendly heat - from the CodeRanch trailboss