java的基础数据
基础数据类型(整数型)
byte---> 2的8次方(取值范围)
256
-127---128
short---> 2的16次方
int--->2的32次方
long--->2的64次方
浮点类型
float---单精度浮点类型8
double----双精度16
布尔类型
boolean 结果只有(true, false)
字符型
char 指的是一个字符
可以写一个汉字
可以写一个字母
字符串 String
char的数组构成
运算符
二元运算符
+ - * / %
>> <<
+= -= *= /= %=
一元运算符
++, --
关系运算符
>, <, >=, <=, !=, ==
逻辑运算符
&
true&&false---短路运算符
|
|| ---短路
^ 异或
例题:
1. int a = 3;
System.out.println(a++);-----3
System.out.println(a);---- 4
System.out.println(--a);---- 3
int c = 5 - (a--);-------- c=2
System.out.println("c的值:" + c);
boolean b = a == 2;
System.out.println(b);------ true
b = b && (a < c--) ? false : true;
int d = b ? 7 : 9;-------d=7
int e = d + 12;
c *= 3;
System.out.println("c的值:" + c);---- c=3
System.out.println("e的值:" + e);----e=19
int f = ((++e == c) ? 25 : 35) + (++a);
System.out.println("f的值:" + f);---- 38
2.
int a, b, c;
a = c = 8;
b = a++; //b=9
System.out.println("a的值:" + a);//9
System.out.println("b的值:" + b);//8
System.out.println("c的值:" + c);//8
short d = 3;
long e1 = d++ + a; // e1 = 12
long e2 = d++ + a++; //e2 = 13 d = 5 a = 10
System.out.println("e1的值:" + e1);
System.out.println("e2的值:" + e2);
boolean b1 = false;
boolean b2 = !b1; // b2 = true
float g = b2 ? a : b; // g = 10.0
System.out.println("++g的值:" + (++g)); // 11.0
double h = g -= 1; // h = 10.0 g = 10.0
System.out.println("h的值:" + h);
boolean b3 = g == 10; // b3 = true
char s = b3 ? 'a' : 'b';//(b=98) a=97
int i = 2 * s;
System.out.println("i的值:" + i);//194