辽宁省网站建设_网站建设公司_SSL证书_seo优化
2026/1/16 21:18:32 网站建设 项目流程

常量

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);//13System.out.println(10-3);//7System.out.println(10*3);//30System.out.println(10/3);//3System.out.println(10.0/3);System.out.println(10/3);}
}

需要专业的网站建设服务?

联系我们获取免费的网站建设咨询和方案报价,让我们帮助您实现业务目标

立即咨询