java数据类型

整数类型:long(64),int(32),short(16),byte(8);
当数据超出最大值时可造成数据的溢出,应使用强制转换

public class 第一个 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int max=Integer.MAX_VALUE;
		 System.out.println("整型最大值:"+max);
        System.out.println("整型最大值+1:"+(max+1));
        System.out.println("整型最大值+2:"+(max+2L));
        System.out.println("整型最大值+2:"+((long)max+2));
	}

}

结果:整型最大值:2147483647
整型最大值+1:-2147483648
整型最大值+2:2147483649
整型最大值+2:2147483649
integer属于包装类,最大作用于字符串与整型的转换,,MAX_VALUE必须大写
字符类型:char(16)位,两个字符。
几个常用转义字符

public class 第一个 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		char ch1='\"';
				char ch2='\\';
						char ch3='\n';
								char ch4='\b';
										;
		 System.out.println("ch1="+ch1);
        System.out.println("ch2="+ch2);
        System.out.println("ch3="+ch3);
        System.out.println("ch4="+ch4);
	}

}

结果:ch1="
ch2=
ch3=

ch4=
浮点型:float(32),double(64);
布尔型:Boolean(true、false)
数据类型的自动转换:1:转换前的数据类型与转换后的数据类型兼容;
转换后的数据类型的表示范围比转换前的类型大;

public class 第一个 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int x=30;
		float y=22.19f;
		 System.out.println("x/y="+(x/y));
        System.out.println("10/3.5="+(10/3.5));
        System.out.println("10/3="+(10/3));
        System.out.println("");
	}

}

结果:x/y=1.3519603
10/3.5=2.857142857142857
10/3=3
int与float做计算,变为float型,int与int还是int
选择与循环语句
选择语句:if;if…else,switch…break;
循环语句:while,do…while,for,循环嵌套;
循环中断:break(从break开始,下面循环的语句不执行了,跳出循环)
continue:执行至continue时,回到循环起点,继续执行循环主体的部分语句

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值