【操作符】 - 数据类型,直接常量

一:数据类型的种类:



1.1 整数类型:byte,short,int,long
四中类型都有正负值,区别在于存储值的范围。但是在实际应用中,大多数时间都会使用int或者long类型。因为,虽然byte和short类型虽然能够节省一部分内存,但是除非有很多那种类型的值需要存储,否则不要使用,这是由于在计算中使用它们还会增加复杂度,所以除非绝对必要,否则一般不应该使用它们。当然,从某些外部源读取数据时,例如一个硬盘文件,必须让每个数据值的类型与原始类型对应。

1.2 浮点数据类型:float,double



boolean
char
long

1.3 数据类型转换

二:直接常量

下面例子中定义的i1,l1,f1等等都可以称之为“直接常量”。

另外注意 Integer.toBinaryString() 方法:

package haizhu.com;

public class Caozuofu {
	public static void main(String[] args) {
		int i1 = 0x2f;
		System.out.println(Integer.toBinaryString(i1));
		int i2 = 0x2F;
		System.out.println(Integer.toBinaryString(i2));
		int i3 = 0177;
		System.out.println(Integer.toBinaryString(i3));
		char c = 0xffff;
		System.out.println(Integer.toBinaryString(c));
		byte b = 0x7f;
		System.out.println(Integer.toBinaryString(b));
		short s = 0x7fff;
		System.out.println(Integer.toBinaryString(s));
		long l1 = 200;
		System.out.println(l1);
		long l2 = 200l;
		System.out.println(l2);
		long l3 = 200L;
		System.out.println(l3);
		double d1 = 200;
		System.out.println(d1);
		double d2 = 200d;
		System.out.println(d2);
		double d3 = 200D;
		System.out.println(d3);
		float f1 = 200;
		System.out.println(f1);
		float f2 = 200f;
		System.out.println(f2);
		float f3 = 200F;
		System.out.println(f3);
	}
}
运行结果:

101111
101111
1111111
1111111111111111
1111111
111111111111111
200
200
200
200.0
200.0
200.0
200.0
200.0
200.0

三:问题:数据类型的详解,用法,区别




  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值