基本运算符
1 package operation; 2 3 public class Demo1 { 4 public static void main(String[] args) { 5 //二元运算符 6 //Ctrl+D :复制当前行到下一行 7 int a=10; 8 int b=20; 9 int c=30; 10 int d=40; 11 12 System.out.println(a+b); 13 System.out.println(a-b); 14 System.out.println(a*b); 15 System.out.println(a/(double)b); 16 } 17 }
1 package operation; 2 3 public class Demo2 { 4 public static void main(String[] args) { 5 6 // 运算结果按照类型的优先级 7 // 类型转换:byte、short、char用运算符运算后自动转型为int类型 8 long a =123123123123L; 9 int b =123; 10 short c =10; 11 byte d =8; 12 13 System.out.println(a+b+c+d);//long 14 System.out.println(b+c+d);//int 15 System.out.println(c+d);//int 16 17 //关系运算符f返回的结果:正确,错误 布尔值 18 19 int a2 = 10; 20 int b2 = 20; 21 int c2 = 22; 22 //取余,模运算 23 System.out.println(c2%a2); 24 25 System.out.println(a2>b2); 26 System.out.println(a2<b2); 27 System.out.println(a2==b2); 28 System.out.println(a2!=b2); 29 30 31 } 32 }