基本数据结构

基本数据结构总共有八种,我将针对其简单应用做个总结。

1.整型int: 4个字节
2.短整型short: 2个字节
3.长整型long: 8个字节
4.单精度浮点类型float:4个字节
5.双精度浮点类型double:8个字节

public static void main1(String[] args) {
		int a = 10;
		long b = 20L;//8
		double c = 12.5;//8
		System.out.println("a = " + a);
		System.out.println("b = " + b);
		System.out.println("c = " + c);
	}
public static void main(String[] args) {
        //短整型   short   2  -32768‬ -  32767
        short s = 32767;
        System.out.println(s);
        System.out.println(Short.MAX_VALUE);
    }
public static void main3(String[] args) {
		int a = 1;
		int b = 2;
		//两个整形若相除,并不会保存小数;
		System.out.println(a/b);//0

		double c = 1.1;
		double d = 1.1;
		System.out.println(c*d);//1.2100000000002
		//程序中小数存储方式不一样;
	}
public static void main4(String[] args) {
    	float e = 12.5f;
    	System.out.println(e);//12.5

    	double f = 1.0D;
    	System.out.println(f);//1.0
    	//优先使用double
    }

6.字符型char:2个字节(整型)

public static void main5(String[] args) {
    	//字符型
    	//java中字符型为两个字节,Unicode字符集;>  C中ASCII码字符集
    	char c = 'a';
    	char d = '高';
    	System.out.println(c);
    	System.out.println(d);

    	int f = c;
    	System.out.println(f);//97 (a = 97);
    }

7.字节类型byte:1个字节(整型)

public static void main5(String[] args) {
		//字节类型   byte   1  -2^7  -  2^7-1
		//-128   127
		//
		//总结来说,给变量赋值的时候,赋值的值不能够超过
		//其能够表达的范围
		
		byte b = 127;
		System.out.println(b);

		//如果进行直接赋值,就是把一个越界的数字给对应的类型
		//这种情况下会报错。
		int c = 214748364;
		System.out.println(c);

		int a = Integer.MAX_VALUE+1;
		System.out.println(a);
		System.out.println(Integer.MAX_VALUE+1);
	}

8.布尔类型:没有明确规定大小,只有 true 和 false 。

public static void main6(String[] args) {
    	//布尔类型  true  false
    	boolean b = true;
    	System.out.println(b);
    }

每一个程序都只有一个main入口,若不实行,可修改main函数的名称,如上图。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值