How Java converts numbers of char types to numbers of type int instead of ASCII

Source: Internet
Author: User

How to convert char ' 3 ' to int 3, you should know that you cannot convert directly, so get the ASCII of ' 3 '. As below:

 Public class leet {    publicstaticvoid  main (string[] args) {        char c = ' 5 ';         int i = C;        System.out.println (i);    }}

The result is an ASCII code:

So how exactly does it turn into the type of int data that's really going to be used, the simplest way, char type character minus ' 0 ' on it, directly on the code:

1  Public class leet {2      Public Static void Main (string[] args) {3         char c = ' 5 '; 4         int i = c-' 0 '; // minus ' 0 ' is the type of int data you want. 5         System.out.println (i); 6     }7 }

How Java Converts a number of type char to a number of type int, not ASCII

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.