Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - Dude, I'm new to java. Excuse me, why can I directly convert the number of characters into the integer "-48"? Thank you in advance for your sincere advice.
Dude, I'm new to java. Excuse me, why can I directly convert the number of characters into the integer "-48"? Thank you in advance for your sincere advice.
In java, when a value or variable with a small range is directly assigned to another variable with a large range, the system can automatically convert.

Automatic type conversion: the data value type on the left side of the arrow can be automatically converted to the data value type on the right side of the arrow.

Metaphor: the water in a small bottle is poured into the water in a big bottle (no problem)

char a = ' 4

int b;

b = a-' 0 '; //char is automatically converted to int type, and each character has an ascii code value. The ascii code value of "0" is 48, while the ascii code value of "4" is 52, so 52-48=4 is regarded as a normal conversion to an integer value.

Summary: Every character number must be reduced by' 0' before it can be converted into an integer, because the number of char characters exists in the form of ascii code in the computer.