运算符2(位运算、字符串连接符及三元运算符)
第九天学习记录
2021.3.4
运算符2
位运算
public class Demo05{ 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 0011 3 0000 0100 4 0000 1000 8 0001 0000 16 */ System.out.println(2<<3);//16 } }
字符串连接符及三元运算符
public class Demo06{ public static void main(String[] args){ int a = 10; int b = 20; //字符串连接符 System.out.println(""+a+b); //1020 System.out.println(a+b+""); //30 //三元运算符 //x?y:z //如果x为true,则结果为y,否则为z int score = 80; String type = score<60?"不及格":"及格"; System.out.println(type); } }
一些工具类的使用
public class Demo04{ public static void main(String[] args){ //幂运算 2^3 很多运算会使用一些工具类来操作 double pow = Math.pow(2,3); System.out.println(pow); } }
包机制
一般用公司域名倒置作为包名 包名统一小写,统一使用单数形式
上一篇:
IDEA上Java项目控制台中文乱码