public class Test01 {
public static void main(String[] args) {
//二元运算符
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);
}
}
public class Test02 {
public static void main(String[] args) {
long a=111111111111L;
int b=123;
short c=10;
byte d=8;
System.out.println(a+b+c+d);//Long
System.out.println(b+c+d);//Int
System.out.println((double)c+d);//Int
}
}
public class Test03 {
public static void main(String[] args) {
int a = 10;
int b = 20;
int c =21;
System.out.println(a<b);
System.out.println(a>b);
System.out.println(a==b);
System.out.println(a!=b);
System.out.println(c%a);// 21 /10=2
}
}
public class Test04 {
public static void main(String[] args) {
int a=3;
int b =a++;//a++ 表示先赋值给b,然后自身加一即3+1,然后传给下面一行
int c=++a;a++; //表示先自身加一即4+1,然后赋值给c(c=5),然后传给下面一行
System.out.println(a);
System.out.println(b);
System.out.println(c);
//幂运算 2^3
double pow= Math.pow(2,3);
System.out.println(pow);
}
}
public class Test05 {
public static void main(String[] args) {
//&&与 (and) ||或 (or) !非(取反)
boolean a=true;
boolean b=false;
System.out.println("a && b:"+(a&&b));//两个都为true,结果为true
System.out.println("a || b:"+(a||b));//两个一个为true,结果为true
System.out.println("!(a && b):"+!(a&&b));//如果是真,则结果为假
//短路运算
int c=5;
boolean d= ((c<4)&&(c++<5));
System.out.println(c);
System.out.println(d);
}
}
public class Test06 {
public static void main(String[] args) {
/*
A=0011 1100
B=0000 1101
A&B=0000 1100 异运算
A|B=0011 1101 或运算
A^B=0011 0001 异或运算 相同得0,不同得1
-B =1111 0010 位运算
2*8 =16 2*2*2*2
效率极高
<< *2 <<表示向左移一位
>> /2
0000 0000 0
0000 0001 1
0000 0010 2
0000 0100 4
0000 1000 8
0001 0000 16
*/
System.out.println(2<<3);
}
}
public class Test07 {
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 Test08 {
public static void main(String[] args) {
//x ? y :z
// 如果x==true,则结果为y,否则结果为z
int score=80;
String type=score<60 ?"不及格":"及格";
System.out.println(type);
}
}
标签:String,int,Day3,System,println,public,out
From: https://www.cnblogs.com/determine-boke/p/17988185