常量

常量

1.概述:在代码运行中,值不会发生改变的数据
2.分类:
    整数常量:所有整数
    小数常量:所有带小数点的
    	2.5   2.0   2.1
    字符常量:带单引号的''单引号有且只能有一个内容
    '1'(算)  '11'(不算) ''(不算)  'al'(不算)
    ' '(算)  '  '(两个空格不算)
    '	'(一个tab键算)
    
	字符串常量:带双引号的"" 双引号内容随意
        ""  " hellowworld"
     布尔常量: true(真)flase(假)->这两个单词不要加双引号
    "true"(这样写属于字符串,不属于布尔常量)
     
     空常量:null 代表的是数据不存在

常量代码

public class Demo01Constant{
    public static void main(string[] args){
		//整数常量
        System.out.println(1);
        System.out println(-1);
        
        //小数常量
        System.out.println(1.5);
        System.out println(1.0);
        
        //字符常量  单引号中必须有且只能有一个内容
        System.out.println('1');
        //System.out.println('11');这是错误的
        System.out.println(' ');
        //System.out.println('    ');四个空格算四个内容,所以不属于
        System.out.println('	');//一个tab算一个内容
        
        //字符串常量
        system.out.println(" sdfsfsef");
        
        //布尔常量
        System.out.println(true);
        System.out.println(false);
        
        //空常量 不能直接使用
        System.out.println(null);
    }
}

常量运算

public class Demo02Constant{
    public static void main(String[] args){
        System.out.println(10+3);//13
        System.out.println(10-3);//7
        System.out.println(10*3);//30
        
        System.out.println(10/3);//3
        System.out.println(10.0/3);
        System.out.println(10/3);
    }
}
posted @ 2026-01-16 21:15  何小德  阅读(1)  评论(0)    收藏  举报