八种基本数据类型

 

 

                                                       重点知识【要牢记】

public class Demo01{
	/**
	* 八种基本数据类型;除了这8种数据类型之外,其它的任意类型被称为引用数据类型;
	* byte

	* short

	* int 

	* long

	* float 

	* double 

	* char 

	* boolean
	*/
	public static void main(String[] args){
		// 1. byte类型的使用
		// byte表示数据类型是byte类型的;
		// b1, 变量名称叫b1
		// = , 赋值操作, 表示把3赋值给变量b1
		// 3, 表示变量的值;
		// 声明并且赋值. 还可以先声明变量,然后再给变量进行赋值;
		byte b1 = 3;
		System.out.println(b1);
		System.out.println("---------------------");
		// 声明一个变量,名称是b2. 没有赋值呢;
		byte b2;
		// 赋值操作;
		b2 = 10;
		System.out.println(b2);
		System.out.println("---------------------");
		// byte b3 = 1024; // 错误: 不兼容的类型: 从int转换到byte可能会有损失
		// System.out.println(b3);

		// 数据类型有不同的表示范围;

		int i1 = 10;
		int i2 = 100;
		int i3 = 10000;
		System.out.println("---------------------");
		System.out.println(i1);
		System.out.println(i2);
		System.out.println(i3);

		short s1 = 10;
		short s2 = 1024;
		System.out.println("---------------------");
		System.out.println(s1);
		System.out.println(s2);

		long l1 = 90L; // 表示long类型的数值; 大写/小写l都可以;推荐使用大写;
		long l2 = 91L;

		float f1 = 90.2313214F; // 表示浮点型 -- 小数.
		float f2 = 12421.23429993F; 
		System.out.println(f1);
		System.out.println(f2);

		double d1 = 123421.2312312D;
		double d2 = 1231232.23423D;
		System.out.println("---------------------");
		System.out.println(d1);
		System.out.println(d2);


		// char类型数据
		char c1 = 'a';
		char c2 = 'b';
		// char c3 = '中华'; // 字符只能写一个中文文字, 如果是多个那么使用双引号引起来;表示字符串
		// "中华"
		System.out.println("---------------------");
		System.out.println(c1);
		System.out.println(c2);
		// System.out.println(c3);
		System.out.println("中华"); // ""引起来的称为字符串

		System.out.println("---------------------");
		// boolean, 两个值.true/fales. 
		boolean isBoy = false;
		boolean isGoodGoodStudy = true;
		System.out.println(isBoy);
		System.out.println(isGoodGoodStudy);
	}
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值