运算符分为
算术运算符 + - * / %(取余,Java里面也叫模运算)
赋值运算符 += -= == !=
关系运算符 > < =
逻辑运算符&&(与) ||(或) !(非)
三元运算符? :
位运算符 >> << & | ^ ~
public static void main(String[] args){
//ctrl + D:复制当前行到下一行
long a = 1231351L;//long类型的后面都要加L
int b = 120;
short c = 30;
byte b = 40;
System.out.println(a+b+c+d);//long
System.out.println(b+c+d);//int
System.out.println(c+d);//int
}
public class demo2 {
public static void main(String[] args) {
//关系运算符返回的结果: 正确,错误
int a = 10;
int b = 20;
System.out.println(a>b);
System.out.println(a<b);
System.out.println(a==b);
System.out.println(a!=b);
}
public class Demo03 {
public static void main(String[] args) {
//++ -- 自增, 自减
int a = 10;
int b = 20;
int c = 30;
b = a++; //先把a的值赋给b 然后a在自身自增
c = ++a; //a自身先增,然后把a的值赋给c
System.out.println(b);
System.out.println(c);
double pow = Math.pow(3, 2);
System.out.println(pow);
//---------------------------------------------
//逻辑运算符
// 与(and) 或(or) 非(取反)
boolean e = true;
boolean f = false;
System.out.println("a %% b:"+(e&&f));//逻辑 与 运算:两个都为真,结果才为真
System.out.println("a || b:"+(e||f));//逻辑 或 运算:两个只要其中一个为真,结果就是真
System.out.println("!(a && b):"+!(e&&f));//逻辑 非 运算:结果为真就为假,结果为假就为真
//短路运算
int o = 5;
boolean p = (o<4)&&(pow++<4);
System.out.println(p);
System.out.println(o);
}
public class Demo04 {
public static void main(String[] args) {
/*
A = 0011 1100
B = 0000 1101
A&B = 0000 1100 //上下两个都为 1,才为 1
A|B = 0011 1101 //上下只要有一个为 1,才为 1
A^B = 0011 0001 //上下位置只要相同就等于它相同的那个数字
~B = 1111 0010 //跟所属的数相反
2 * 8 = 16 2*2*2*2
效率极高!
<< *2
>> /2
*/
}
public class Demo05 {
public static void main(String[] args) {
int a = 10;
int b = 20;
a+=b;//a=a+b
a-=b;//a=a-b
System.out.println(a);
//字符串连接符 + , String
System.out.println(""+a+b);
System.out.println(a+b+"");
}
public class Demo06 {
public static void main(String[] args) {
//x ? y : z
//如果x==true,则结果为y,否则结果为z
int score = 80;
String type = score < 60?"及格":"不及格";
System.out.println(type);
}
import com.yuan.base.*;//导入这个包中所有的数据
public class Demo07 {
public static void main(String[] args) {
//包的本质为文件夹
//一般公司要用域名倒置写
}