2014年5月17日星期六

A small problem of self- discovery request advice

java
public class ForDemo {
public static void main (String [] args) {
char c1 = '2 ';
int b1 = c1 + '0 ';
int b2 = c1 - '0 ';
System.out.println ("b1:" + b1 + "" + "b2:" + b2);
}
compile the results of b1: 98 b2: 2 b1 and b2
Why is not the same as a result of it ? Sin seeking advice
------ Solution ------------------------------------- -------
character 2 and 0 , respectively, corresponding ASCII code
50 and 48
------ Solution ----------------------------- ---------------
implicit conversion has called automatic type conversion. Type conversion done automatically by the system .
types range from small to large storage storage range type:
byte -> short (char) -> int-> long-> float-> double
will first char to int type conversion when calculating type , corresponding to 50,48 , and then performing the calculation
------ Solution -------------- ------------------------------
automatic type conversion of
------ Solution --- -----------------------------------------
character do you use subtraction in fact, when the operation system will first check the character code table , find the corresponding number, then use that number to make calculations, the results have come out of this digital code table to find the corresponding character , so it 's not the same display .
------ For reference only -------------------------------------- -
upstairs , the landlord is unclear stopwatch problem ah
------ For reference only ---------------------- -----------------
very detailed Thank you! understand the

没有评论:

发表评论