day4:Java运算符
package operator;
public class Operator {
public static void main(String[] args) {
//ctrl+D 复制当强行到下一行
int a=100;
int b=21;
int c=110;
int d=200;
System.out.println(a+b);
System.out.println(a-b);
System.out.println(a*c);
System.out.println((double)a/(double)d);//数据类型强制转换 否者运算会出错
System.out.println("========================================");
System.out.println(a>b);//关系运算符返回结构为bool值 true false
System.out.println(a
System.out.println(a==b);
System.out.println(2*a==d);
System.out.println("========================================");
System.out.println(a%b);//取余运算
System.out.println(a%c);
System.out.println(a%d);
System.out.println("========================================");
//++ -- 运算符
System.out.println(a++); //a++ 先赋值后加一
System.out.println(++a); //--a 先运算后赋值
System.out.println(a--);
System.out.println(--a);
System.out.println("========================================");
//幂运算
double f=Math.pow(2,3);
double g=Math.pow(2,4);
double h=Math.pow(4,1);
System.out.println(f);
System.out.println(g);
System.out.println(h);
System.out.println("========================================");
boolean b1=true;
boolean b2=false;
System.out.println("b1&b2="+(b1&&b2));//与运算
System.out.println("b1||b2="+(b1||b2));//或运算
System.out.println("!b1="+(!b1));//非运算
//短路运算:若与符号前为false则后面不进行运算结果直接判断为false;
System.out.println("========================================");
//<< >> :左移 右移 <<:>>:/2
System.out.println(2<<4);
System.out.println(64>>4);
System.out.println("========================================");
//位运算符
int i=0b00101011;
int j=0b01100011;
int k=0b11101111;
System.out.println(i&j);
System.out.println(i|j);
System.out.println(~k);
System.out.println("========================================");
//扩展斧子运算符
System.out.println(a+=b);//a=a+b
System.out.println(a-=b);//a=a-b
System.out.println(a*=b);//a=a*b
System.out.println(a/=b);//a=a/b
//字符串连接符
System.out.println("cd"+a+b);//加号前遇见字符串类型会将后面也转化为字符穿类型进行拼接
System.out.println(a+b+"cd");//若先遇见运算则先运算后进行字符串拼接
System.out.println("========================================");
//三元运算符
int score=70;
String str= score>60?"及格":"不及格";
System.out.println(str);
int score2=59;
String str2= score2>60?"及格":"不及格";
System.out.println(str2);
}
}
标签:Java,运算,int,System,运算符,println,out
来源: https://www.cnblogs.com/lzggYa/p/14419739.html