Java04
一、运算符

1 public class Demo01 { 2 public static void main(String[] args) { 3 // 二元运算符 4 // Ctrl + D : 复制当前行到下一行 5 int a = 10; 6 int b = 20; 7 int c = 25; 8 int d = 25; 9 10 System.out.println(a+b); 11 System.out.println(a-b); 12 System.out.println(a*b); 13 System.out.println((double)a/b); 14 } 15 }
1 public class Demo02 { 2 public static void main(String[] args) { 3 long a = 123123123123123L; 4 int b = 123; 5 short c = 10; 6 byte d = 8; 7 8 System.out.println(a+b+c+d);//long 9 System.out.println(b+c+d);//int 10 System.out.println(c+d);//int 11 } 12 }
1 public class Demo03 { 2 public static void main(String[] args) { 3 int a = 10; 4 int b = 20; 5 int c = 21; 6 7 System.out.println(c%a); 8 9 System.out.println(a>b); 10 System.out.println(a<b); 11 System.out.println(a==b); 12 System.out.println(a!=b); 13 } 14 }
1 public class Demo04 { 2 public static void main(String[] args) { 3 // ++ -- 自增 自减 一元运算符 4 int a = 3; 5 int b = a++;// 执行完这行代码后,先给b赋值,再自增 6 7 System.out.println(a); 8 9 int c = ++a;// 执行完这行代码后,先自增,再给b赋值 10 11 System.out.println(a); 12 System.out.println(b); 13 System.out.println(c); 14 15 //幂运算 2^3 = 8 很多运算,会使用一些工具类进行操作 16 double pow = Math.pow(2, 3); 17 System.out.println(pow); 18 19 } 20 }
1 //逻辑运算符 2 public class Demo05 { 3 public static void main(String[] args) { 4 // 与(and) 或(or) 非(取反) 5 boolean a = true; 6 boolean b = false; 7 8 System.out.println("a && b:"+(a&&b));//逻辑与运算 9 System.out.println("a || b:"+(a||b));//逻辑或运算 10 System.out.println("!(a && b):"+!(a&&b));//取反 11 12 //短路运算 13 int c = 5; 14 boolean d = (c<4)&&(c++<4); 15 System.out.println(d); 16 System.out.println(c); 17 } 18 }
1 public class Demo06 { 2 public static void main(String[] args) { 3 /* 4 A = 0011 1100 5 B = 0000 1101 6 ------------------------------------- 7 A&B = 0000 1100 8 A|B = 0011 1101 9 A^B = 0011 0001 异或:相同为0不同为1 10 ~B = 1111 0010 11 12 2*8 = 16 13 << *2 >> /2 14 15 位运算效率极高 16 */ 17 18 System.out.println(2<<3); 19 } 20 }
1 public class Demo07 { 2 public static void main(String[] args) { 3 int a = 10; 4 int b = 20; 5 6 a+= b;// a = a+b 7 a-= b;// a = a-b 8 9 System.out.println(a); 10 11 System.out.println(a+b); 12 //字符串连接符 + , String 13 System.out.println(""+a+b); 14 System.out.println(a+b+""); 15 } 16 }
1 public class Demo08 { 2 public static void main(String[] args) { 3 // x ? y : z 4 // 如果x==true,则结果为y,否则结果为z 5 6 int score = 80; 7 String type = score < 60 ?"不及格":"及格"; 8 System.out.println(type); 9 } 10 }
二、包机制
包:文件夹
一般利用公司域名倒置作为包名 com.baidu.www
package ... 必须位于最上方
导入包:import package ...
三、JavaDoc

打开java文件所在文件夹,执行cmd
输入 javadoc -encoding UTF-8 -charset UTF-8 Demo01.java

浙公网安备 33010602011771号