day03(运算符)
Test01:
public class Test01 {
public static void main(String[] args)
{
//作用域1
//{中间的代码段 代码可以是一行 也可以是多行}
int i = 10;
int j = 10;
int m = 10;
int n = 10;
//double i = 2.0;
int minAge = 10;
int x = 0;
//解释代码
/*
int tmp = minAge;
minAge = minAge+1;
x = tmp;
*/
//System.out.println("x:"+x);
System.out.println("minAge:"+minAge);
System.out.println(i++); //先使用 后+1
//j = j+1;
//int tmp = j;
//j = tmp;
System.out.println(++j); //先+1 后使用
System.out.println(m--); //先使用 后-1
System.out.println(--n); //先-1 后使用
System.out.println("-----------");
System.out.println(i++);
System.out.println(++j);
System.out.println(m--);
System.out.println(--n);
//i = 1>3 ? 10:100;
//System.out.println(i);
//String s = null;
//System.out.println(s==null);
/* 总结规律 绝对值求值 符号看%前面
5%2 1 5%-2 1 -5%2 -1 -5%-2 -1
*/
/*求值
* int m= 20;
* int n= 20;
* 求 m>=n m<=n
*/
/*求值
* int x = 10;
* int y = 10;
* 求 x==y x!=y;
* */
/*求值
* String s = null;
* 求 s == null;
*/
/*求值
* int i =2; int j = 30
* 求 i大于40 且j小于50的结果
* 求 i大于40 或j小于50的结果
* 求 i大于10 且j小于50的结果
* */
// 控制台输入一个整数 判断该整数是奇数还是偶数 打印出来
}
}
Test02:
public class Test02 {
public static void main(String[] args)
{
Scanner f = new Scanner(System.in);
int num = f.nextInt();
String result = num%2==0 ? "偶数" : "奇数";
System.out.println(result);
}
}
Test03:
public class Test03 {
public static void main(String[] args)
{
/*
int i = 3&7;
int j = -3&-7;
System.out.println(i);
System.out.println(j);
*/
//1111 1101 -3补码
//0000 0111 7的原码
//1111 1111
//1111 1110
//1000 0001 -1
int k = -3 | 7;
//1111 1101 -3补码
//0000 0010 2
int m = ~(-3);
//0000 0011 3原码
//1111 1100 补
//1111 1011 反
//1000 0100 -4
int n = ~(3);
//1111 1101 -3补码
//0000 0111
//1111 1010
//1111 1001
//1000 0110 -6
int l = -3^7;
System.out.println(k);
System.out.println(m);
System.out.println(n);
System.out.println(l);
System.out.println(255^2565256^2565256);
}
}
Test04:
public class Test04 {
public static void main(String[] args)
{
//2
//1000 0010
//0000 1000
//0001 0000
//3
//0000 0011
//0000 1100
//3
//1111 ............ 1000 1000
//1000 1000 -8的原码
//1111 0111 反码
//1111 1000 补码
//1111 1110 0000 左移两位后的补码
//1111 1101 1111 取反
//1010 0000 原码
//-8右移两位
//1000 1000 -8的原码
//1111 0111 反码
//1111 1000 补码
//1111 1110 右移两位
//1111 1101
//1000 0010
System.out.println(-8<<2);
//求 -0x7fffffff左移一位
//1111 1111 1111 1111 1111 1111 1111 1111
//1000 0000 0000 0000 0000 0000 0000 0000
//1000 0000 0000 0000 0000 0000 0000 0001
//(1) 0000 0000 0000 0000 0000 0000 0000 0010 2
}
}
Test05:
public class Test05 {
public static void main(String[] args)
{
String ip = "192.168.5.2";
int i = 0x4c8; //0100 1100 1000
int mask = 0xf;//1111 掩码
System.out.println(i&mask);
}
}
Test06:
public class Test06 {
public static void main(String[] args)
{
System.out.println("睁眼");
System.out.println("刷牙");
System.out.println("洗脸");
System.out.println("吃早饭");
int money = 1;
if(money == 1)
{
//假如身上一块钱
System.out.println("吃油条");
}
else
{
//假如身上五块钱
System.out.println("煎饼");
//假如身上十块钱
System.out.println("煎饼+豆浆+茶叶蛋");
//假如身上一万块钱
System.out.println("土豪");
}
System.out.println("睁眼");
System.out.println("上班");
}
}