println和print区别
- println:输出时换行
- print:输出时不换行
常量
- 概述:在代码的运行过程中,值不会发生改变的数据
- 分类:
- 整数常量:所有整数
- 小数常量:所有带小数点的,2.5 1.5 2.0
- 字符常量:带单引号的‘ ’单引号中必须有且只能有一个内容,‘1’(算) ’11‘(不算),‘’(不算),‘a1’(不算),‘ ’(算)
- 字符串常量:带双引号的“” 双引号中内容随意,“” “helloworld”
- 布尔常量:true(真)、false(假)
- 空常量: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(' ');
System.out.println(' ');
System.out.println("皆过客,揽星河");
System.out.println("");
System.out.println(true);
System.out.println(false);
}
}
常量的运算
public class Demo02Constant{
public static void main(String[] args){
System.out.println(10+3);
System.out.println(10-3);
System.out.println(10*3);
System.out.println(10/3);
System.out.println(10.0/3);
System.out.println(10/3.0);
}
}