1 package base;
2
3 public class Demo06 {
4 public static void main(String[] args) {
5 //以下是加减乘除
6 long a=10000000000000000L;
7 int b=1000;
8 short c=100;
9 byte d=100;
10 //任何非long整数做运算,结果总是int型 有long就是long
11 System.out.println(a+b+c+d); //10000000000001200
12 System.out.println(b+c+d); //1200
13 System.out.println(c+d); //200
14
15 // 以下是自增,自减
16 int num1=7; // 7+1
17 int num2=num1++; // 7+1
18 int num3=++num2; // 1+7
19 System.out.println(num1);
20 System.out.println(num2);
21 System.out.println(num3);
22
23 //以下是关系运算符
24 int number1=10;
25 int number2=20;
26 System.out.println(number1<number2); //true
27 System.out.println(number1>number2); //false
28 System.out.println(number1==number2); //false
29 System.out.println(number1!=number2); //true
30
31 //逻辑运算符&&,||,!
32 boolean tr=true;
33 boolean fa=false;
34 System.out.println(tr&&fa); //false
35 System.out.println(tr||fa); //true
36 System.out.println(!tr); //false
37
38 //条件运算符 x?y:z x为true则返回y,否则为z
39 int score=100;
40 String jie=score>60?"及格":"不及格";
41 System.out.println(jie); // 及格
42
43 //幂运算 2^3 2*2*2=8 很多运算,我们会使用一些工具类来操作
44 double mi=Math.pow(2,3);
45 System.out.println(mi); // 8.0
46
47 //位运算符,仅需了解即可,主要针对二进制
48 /*
49 * A=0011 1100
50 * B=0000 1101
51 *
52 * A&B=0000 1100 如果都为1则为1,否则为0
53 * A|B=0011 1101 有1个为1则为1
54 * A^B=0011 0001 相同就是0,不同就是1
55 * ~B=1111 0010 取反
56 * */
57
58
59 }
60 }