public class eavl {
public static void main(String[] args) {
int a,b,c;
a=15;
b=a+4;
c=b;
c=b=a+4; //出现两个=,从右往左执行
System.out.print(c);
}
}
/*定义a,b,c;c=b=a+4; //出现两个=,从右往左执行,最后输出c的值*/
a=3;
b=a++ +3
a=4,b=7
a=3;
b=++a +3
a=4,b=6
符号在前先运算再使用
符号在后先使用再运算
逻辑运算符
true&&true==trun
true&&false==false
false&&false==false
&&与:两者都为真,结果才是真。一真一假或两者都为假;结果为假
true||true==trun
true||false==true
falseIIfalse==false
||或:只要一者为真,结果就是真
!true==false
!false==true
!非:非真即假,非假即真
~取反: 0变1, 1变0
^异或:两者相同即为ie,不同为1
位逻辑运算符
& || ~ ^
位移运算符
<<左移:整体左移,空位补0,溢出去掉
>>右移:整体右移,正数补0(还是正数),负数补1(还是负数),溢出去掉
>>>无符号右移:整体右移,空位补0,溢出去掉
a<<1:左移一位
a>>2:右移两位
比较运算符
package third;
public class ysf {
public static void main(String[] args) {
// TODO Auto-generated method stub
int number1=4; //声明int型变量number1
int number2=5; //声明int型变量number2
//依次将变量number1与变量number2的结果输出
System.out.println("number1>number2的返回值为:"+(number1>number2));
System.out.println("number1<number2的返回值为:"+(number1<number2));
System.out.println("number1==number2的返回值为:"+(number1==number2));
System.out.println("number1!=number2的返回值为:"+(number1!=number2));
System.out.println("number1>=number2的返回值为:"+(number1>=number2));
System.out.println("number1<=number2的返回值为:"+(number1<=number2));
}
}
/*int number1=4; //声明int型变量number1;int number2=5; //声明int型变量number2;//依次将变量number1与变量number2的结果输出*/
算术运算符
package third;
import java.util.Scanner;
public class eavl {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in); //创建扫描器,获取键盘输入的值
System.out.println("请输入两个数字,用空格隔开(num1 num2):"); //输入提示
double num1=sc.nextDouble(); //获取键盘输入的double数据存入num1
double num2=sc.nextDouble(); //获取键盘输入的double数据存入num2
System.out.println("num1+num2的和为:"+(num1+num2));
System.out.println("num1-num2的差为:"+(num1-num2));
System.out.println("num1*num2的积为:"+(num1*num2));
System.out.println("num1/num2的商为:"+(num1/num2));
System.out.println("num1%num2的余数为:"+(num1%num2));
sc.close(); //关闭扫描器
}
}
/*Scanner sc=new Scanner(System.in); //创建扫描器,获取键盘输入的值;System.out.println("请输入两个数字,用空格隔开(num1 num2):"); //输入提示;double num1=sc.nextDouble(); //获取键盘输入的double数据存入num1;double num2=sc.nextDouble(); //获取键盘输入的double数据存入num2;将结果输出;sc.close(); //关闭扫描器*/