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