算术运算符:+ , - , * , /, % , ++ , --
int a = 10;
int b = 20;
int c = 25;
int d = 25;
System.out.println(a+b);
System.out.println(a-b);
System.out.println(a*b);
System.out.println(a/(double)b);//强制转换
//++,--
int a = 3;
int b = a++;//执行这行代码后,先给b赋值,再自增
//a++ a=a+1
System.out.println(a);
//a++ a=a+1
int c = ++a;//执行这行代码前,献给b赋值,再自增
System.out.println(a);
System.out.println(b);
System.out.println(c);
//幂运算 2^3 2*2*2=8
double pow = Math.pow(2 , 3);
System.out.println(pow);
赋值匀速符: =
long a = 123123123132l;
int b = 123;
short c = 10;
byte d = 8;
System.out.println(a + b + c);
System.out.println(b + c + d);
System.out.println(c + d);
System.out.println();
关系运算符:> , < , >= , <= , ==, != instanceof
//关系运算符返回的结果: 正确 错误
int a = 10;
int b = 20;
int c = 22;
System.out.println(a > b);
System.out.println(a < b);
System.out.println(a == b);
System.out.println(a != b);
System.out.println(b % c);
注意:
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+"");//字符串如果在后面,前面的会进行计算
逻辑运算符:&& , || , !
// 与(and) 或(or) 非(取反)
boolean a=true;
boolean b=false;
System.out.println("a&&b="+(a&&b));//逻辑与运算:两个变量都为真,结果才为ture
System.out.println("a||b="+(a||b));//逻辑或运算:两个变量只要有一个为真,则结果为ture
System.out.println("!(a&&b)="+!(a&&b));//逻辑非运算:如果是真的,则结果为假,如果为假,结果为真
//短路运算
int c=5;
boolean d=(c<4)&&(c++<4);
System.out.println(d);//显示结果为false
System.out.println(c);//显示结果为4,说明c++没有执行
位运算符 :& , | , ^ , ~ , >> , << , >>> (了解!!!)
条件运算?:
//三元运算符
//x ? y :z
//如果x==ture 结果为y,如果x==false 结果为z
int score =80;
String type = score<60?"不及格":"及格";
System.out.println(type);
扩展赋值运算符 :+= , - = , *= /=
标签:Java,int,基础,System,运算符,++,println,out From: https://www.cnblogs.com/wake-boyang/p/18431361