Automatic conversion of Java data types, with casts

Source: Internet
Author: User

I. Automatic conversion of data types

 Public classtest{ Public Static voidMain (string[] args) {intA = 1; Doubleb = 1.5; DoubleA_b_count = a+b;//when integral and double are added, the result is automatically converted to a double-precision typeString C= "Ling"; Chard = ' Morning '; CharE = ' good '; String c_d_e_content= C+d+e;//when the character type is added to the string type, the result is automatically converted to a string typeSystem.out.println (A_b_count);    System.out.println (c_d_e_content); }}

Ii. Coercion of data types

 Public class test{    publicstaticvoid  main (string[] args) {        int    a    =    (int) 10.2;    // Casting Double-type data to reshape        Double    b    =    (double) ten;    // To cast data of an integral type to a double type         System.out.println (a);        System.out.println (b);    }}

An int and a double can be forced to convert each other.

Char and string types cannot be forced to convert to and from each other.

Automatic conversion of Java data types, with casts

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: 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.