How Java converts char data into int data (GO)

Source: Internet
Author: User

A string, string= "2324234535";
When the number I is taken out of the char type: char Temp=string.charat (i)
How do I convert the char type to int?
I need to find a sum of the mantissa, such as: 123 of the sum of the sum of 6.

Each character is taken out to obtain a char-type 1,2,3,4,5;
But the result of summing is the ASCII code value


Treatment methods:

(1) Turn char into a string, Integer.parseint ("" + ' 1 ')
Or
String a = "12345";
int d = integer.parseint (String.valueof (A.charat (2)));
int c = Integer.parseint (String.valueof (A.charat (3)));
System.out.println (d * c);

Demo

// [0..3] int start=integer.parseint (Drynoinfo.charat (1) + ""); // 0 int end=integer.parseint (Drynoinfo.charat (Drynoinfo.length ()-2) + ""); // 3  for (int i = start; I <=end; i++) {    if (i>start) {                    sbuilder.append ( "|" );    }    Sbuilder.append (i);       }

(2) Chartoint can be directly used Character.digit (char ch, int radix);

http://tieba.baidu.com/p/2062701652

There are two methods of conversion:
One is an automatic conversion, such as char C = 97, which automatically converts 96 of the int type to the ' a ' of char
The other is to force the type conversion, such as int i = 97,char c = (char) I, after doing so, the value of char is also ' a '
Why is it a? Because the ASCII value corresponding to the character ' a ' is 97.
Automatic conversions are generally used for large types to small type conversions, also called narrowing conversions
Coercion type conversions are generally used for small type-to-large type conversions, also called extension conversions




How Java converts char data into int data (GO)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.