2.2.1整数类型(byte, short,int,10ng) ■示例 byte bl \缺省值为0 a byte b2=127 \\赋初值为127 short s1=( short)(b1+b2);\\强制类型转换 short s2=( short)(b1+123)\\强制类型转换 int n=b1+b2;\\不需要强制类型转换 long11=2343;\不需要强制类型转换 long12=4294967296L;\\必须用或1结尾 long13=65536大63356;\\乘法运算越界,13为0 long14=65536*63356;N14为4294967296
◼ 示例 ◼ byte b1; \\ 缺省值为0 ◼ byte b2 = 127; \\ 赋初值为127 ◼ short s1 = (short)(b1 + b2); \\ 强制类型转换 ◼ short s2 = (short)(b1 + 123) \\ 强制类型转换 ◼ int n = b1 + b2; \\ 不需要强制类型转换 ◼ long l1 = 2343; \\ 不需要强制类型转换 ◼ long l2 = 4294967296L; \\ 必须用L或l结尾 ◼ long l3 = 65536*63356; \\ 乘法运算越界,l3为0 ◼ long l4 = 65536L*63356; \\ l4为4294967296L 2.2.1 整数类型(byte, short, int, long)
2.2.1浮点数类型,实型( float, double) ■实型常量 1.十进制数形式 由数字和小数点组成,且必须有小数点,如0.123,123,123,123.0 2.科学计数法形式 如:123e3或123E3,其中e或E之前必须有数字,且e或E后面的指 数必须为整数 ■32位浮点数形式:0.23,123E-4,18F
◼ 实型常量 1. 十进制数形式 由数字和小数点组成,且必须有小数点,如0.123,.123, 123.,123.0 2. 科学计数法形式 如:123e3或123E3,其中e或E之前必须有数字,且e或E后面的指 数必须为整数。 ◼ 32位浮点数形式: 0.23f, 1.23E-4f , . 18F 2.2.1 浮点数类型,实型(float, double)
2.2.1浮点数类型,实型( float, double) 实型变量 类型为foat或 double, float在机器中占32位, double占64位。实型变 量的定义如: double d1=127.0;\\赋初值为127 ■ double d2=127;\\赋初值为127 f1oatf1=127.0f;\必须在数字后加f或F f1oatf2=4.0e38f;\\错误!32位浮点数不能超过 \3.4028234663852886e38 float f3=( float)d1;\、必须强制类型转换
◼ 实型变量 类型为float或double,float在机器中占32位,double占64位。实型变 量的定义如: ◼ double d1 = 127.0; \\ 赋初值为127 ◼ double d2 = 127; \\ 赋初值为127 ◼ float f1 = 127.0f; \\ 必须在数字后加f或F ◼ float f2 = 4.0e38f;\\ 错误!32位浮点数不能超过 \\ 3.4028234663852886e38 ◼ float f3 = (float)d1; \\ 必须强制类型转换 2.2.1浮点数类型,实型(float, double)
2.2.1使用举例 public class assign public static void main(String [] args) Int x, y byte b=3; float z=1.234f double w=1.234 boolean flag=true i char cg C="a; X=120; y=30:
public class Assign { public static void main (String [] args) { int x , y ; byte b = 3; float z = 1.234f ; double w = 1.234 ; boolean flag = true ; char c ; c = ‘ a ‘ ; x = 120 ; y = 30; ...... } } 2.2.1使用举例