变量:
内存中的一个存储区域;该区域有自己的名称(变量名)和类型(数据类型);
Java 中的每个变量必须先声明,后使用;
该区域的数据可以在同一类型范围内不断变化;
时间代码笔记如下:
//变量: //1,java 中的变量定义的格式: 数据类型 变量名 = 初始化值 public class TestVeriable { public static void main(String[] args) { //2.变量得先定义,后使用 int myInt1 = 10; double d = 12.3; System.out.println(myInt1); System.out.println(d); //3.整数: byte(-128 ~ +127) short int long byte b1 = 12; short s1 = 128; int i1 = 12; //定义 long 型变量,值的末尾加 “L” 或者 “l” ; long l1 = 21341234L; System.out.println(i1); System.out.println(l1); System.out.println(b1); System.out.println(s1); //4.浮点型(带小数点的数值):float double double d1 = 12.3; //声明 float 类型的浮点型数据,末尾要加 “F” 或者 “f” ; float f1 = 12.3F; System.out.println(d1); System.out.println(f1); //5.字符型(=两个字节):char 只能表示一个字符(英文,中文,标点符号,日文,。。。); char c1 = 'a'; String str = "ab"; char c3 = '中'; String str1 = "中国"; System.out.println(c1); System.out.println(str); System.out.println(c3); System.out.println(str1); //可以表示转义字符 char c4 = '\t'; char c5 = '\n'; System.out.println("abc"+ c5 +"def"); System.out.println("abc" + c4 + "def"); //了解 char c6 = '\u1234'; System.out.println(c6); //6.布尔类型: boolean 只能够取值为 true 或 false 。 不能取值 null。 boolean bool1 = true; if (bool1) { System.out.println("王老师是个\"帅\"哥"); }else{ System.out.println("你在说谎吗"); } } }
个人微信公众号:“遇见王川”,欢迎关注。