Applies only to basic data types

1: automatic conversion

A: Type compatible B: Small to large (manual conversion is not required)

For example, short s =24; int i =s;

Because the number of bytes of short is: 2; The number of bytes of int is 4;

2: cast:

A: Type compatible. B: From large to small (manual conversion is required), the accuracy will be lost

For example, int I =2; short s =(short)i;

package day_05_25;
* Note: Boolean types cannot be converted to other types * * Default (automatic conversion) : from small to large: * A: Byte -->short,char-->int,float-->long,double * B: byte,short,char, they must first convert to int if they want to participate in the operation. * * Cast: * From a large data type to a small data type * Format: Target data type variable name = (target data type) the data to be converted. * * Note: Do not use casts arbitrarily, because precision is lost. * /
public class Demo_03 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int x =3;
		int y =5;
		System.out.println(x+y);
		byte a = 3;
		int b = 4;
		byte c = (byte)(a+b);
		System.out.println(c);
		
		int i = 20013;
		char ch='the sea';
				i=ch;
		System.out.println(i);
		
		double d=2.23232;
		i=(int)d; System.out.println(i); }}Copy the code