其他分享
首页 > 其他分享> > 08-操作符和数据类型总结

08-操作符和数据类型总结

作者:互联网

目录

1. 自增和自减操作符

public class IncreaseDecrease {
    public static void main(String[] args) {
        int a = 1;
        System.out.println("a++=" + a++); // a++=1
        System.out.println("a=" + a); // a=2


        int b = 10;
        System.out.println("b--=" + b--); // b--=10
        System.out.println("b=" + b); // b=9

    }
}

加加放在变量的后面,其实就是先使用变量的值,然后再执行加加操作,减减同理。

所以,上面的代码可以变成这样来理解:

public class IncreaseDecrease {
    public static void main(String[] args) {
        int a = 1;
        // System.out.println("a++=" + a++);
        System.out.println("a++=" + a);
        a = a + 1;
//      a += 1;
        System.out.println("a=" + a);


        int b = 10;
        System.out.println("b--=" + b--);
        System.out.println("b=" + b);

    }
}

接下来,我们来看看前加加的操作:

public class IncreaseDecrease2 {
    public static void main(String[] args) {
        int a = 1;
        System.out.println("a++=" + a++); // a++=1
        System.out.println("a=" + a); // a=2
        a = 1;
        System.out.println("++a=" + (++a)); // ++a=2
        System.out.println("a=" + a); // a=2


        int b = 10;
        System.out.println("b--=" + b--); // b--=10
        System.out.println("b=" + b); // b=9

        b = 10;
        System.out.println("--b=" + --b); // --b=9
        System.out.println("b=" + b); // b=9
    }
}

接下来看一个分解的代码:

public class IncreaseDecrease3 {
    public static void main(String[] args) {
        int a = 1;
        System.out.println("a++=" + a++); // a++=1

        System.out.println("a++=" + a); // a++=2
        a = a + 1;

        a = 1;

        System.out.println("++a=" + (++a)); // ++a=2

        a = a + 1;
        System.out.println("++a=" + a); // ++a=3
    }
}

2. 打印 26 个连续的字符

public class Print26Chars {
    public static void main(String[] args) {
        char ch = 'A';
        // char ch2 = '\u5234';
        int num = ch;
        System.out.println(num + "\t" + ((char) num++));
        System.out.println(num + "\t" + ((char) num++));
        System.out.println(num + "\t" + ((char) num++));
        System.out.println(num + "\t" + ((char) num++));
        System.out.println(num + "\t" + ((char) num++));
        System.out.println(num + "\t" + ((char) num++));
        System.out.println(num + "\t" + ((char) num++));
        System.out.println(num + "\t" + ((char) num++));
        System.out.println(num + "\t" + ((char) num++));
        System.out.println(num + "\t" + ((char) num++));
        System.out.println(num + "\t" + ((char) num++));
        System.out.println(num + "\t" + ((char) num++));
        System.out.println(num + "\t" + ((char) num++));
        System.out.println(num + "\t" + ((char) num++));
        System.out.println(num + "\t" + ((char) num++));
        System.out.println(num + "\t" + ((char) num++));
        System.out.println(num + "\t" + ((char) num++));
        System.out.println(num + "\t" + ((char) num++));
        System.out.println(num + "\t" + ((char) num++));
        System.out.println(num + "\t" + ((char) num++));
        System.out.println(num + "\t" + ((char) num++));
        System.out.println(num + "\t" + ((char) num++));
        System.out.println(num + "\t" + ((char) num++));
        System.out.println(num + "\t" + ((char) num++));
        System.out.println(num + "\t" + ((char) num++));
        System.out.println(num + "\t" + ((char) num++));

    }
}
65	A
66	B
67	C
68	D
69	E
70	F
71	G
72	H
73	I
74	J
75	K
76	L
77	M
78	N
79	O
80	P
81	Q
82	R
83	S
84	T
85	U
86	V
87	W
88	X
89	Y
90	Z

3. 找到可以被整除的数

public class FindDiv {
    public static void main(String[] args) {
        int dividend = 35;
        int divisor = 9;
        System.out.println(dividend + "可以整除" + divisor + "吗?" + ((dividend++) % divisor == 0));
        System.out.println(dividend + "可以整除" + divisor + "吗?" + ((dividend++) % divisor == 0));
        System.out.println(dividend + "可以整除" + divisor + "吗?" + ((dividend++) % divisor == 0));
        System.out.println(dividend + "可以整除" + divisor + "吗?" + ((dividend++) % divisor == 0));
        System.out.println(dividend + "可以整除" + divisor + "吗?" + ((dividend++) % divisor == 0));
        System.out.println(dividend + "可以整除" + divisor + "吗?" + ((dividend++) % divisor == 0));
        System.out.println(dividend + "可以整除" + divisor + "吗?" + ((dividend++) % divisor == 0));
        System.out.println(dividend + "可以整除" + divisor + "吗?" + ((dividend++) % divisor == 0));
        System.out.println(dividend + "可以整除" + divisor + "吗?" + ((dividend++) % divisor == 0));
        System.out.println(dividend + "可以整除" + divisor + "吗?" + ((dividend++) % divisor == 0));
        System.out.println(dividend + "可以整除" + divisor + "吗?" + ((dividend++) % divisor == 0));
        System.out.println(dividend + "可以整除" + divisor + "吗?" + ((dividend++) % divisor == 0));
        System.out.println(dividend + "可以整除" + divisor + "吗?" + ((dividend++) % divisor == 0));
        System.out.println(dividend + "可以整除" + divisor + "吗?" + ((dividend++) % divisor == 0));
        System.out.println(dividend + "可以整除" + divisor + "吗?" + ((dividend++) % divisor == 0));
        System.out.println(dividend + "可以整除" + divisor + "吗?" + ((dividend++) % divisor == 0));
        System.out.println(dividend + "可以整除" + divisor + "吗?" + ((dividend++) % divisor == 0));
        System.out.println(dividend + "可以整除" + divisor + "吗?" + ((dividend++) % divisor == 0));
        System.out.println(dividend + "可以整除" + divisor + "吗?" + ((dividend++) % divisor == 0));
        System.out.println(dividend + "可以整除" + divisor + "吗?" + ((dividend++) % divisor == 0));
        System.out.println(dividend + "可以整除" + divisor + "吗?" + ((dividend++) % divisor == 0));
        System.out.println(dividend + "可以整除" + divisor + "吗?" + ((dividend++) % divisor == 0));
        System.out.println(dividend + "可以整除" + divisor + "吗?" + ((dividend++) % divisor == 0));
        System.out.println(dividend + "可以整除" + divisor + "吗?" + ((dividend++) % divisor == 0));
        System.out.println(dividend + "可以整除" + divisor + "吗?" + ((dividend++) % divisor == 0));
        System.out.println(dividend + "可以整除" + divisor + "吗?" + ((dividend++) % divisor == 0));
        System.out.println(dividend + "可以整除" + divisor + "吗?" + ((dividend++) % divisor == 0));
        System.out.println(dividend + "可以整除" + divisor + "吗?" + ((dividend++) % divisor == 0));
        System.out.println(dividend + "可以整除" + divisor + "吗?" + ((dividend++) % divisor == 0));
        System.out.println(dividend + "可以整除" + divisor + "吗?" + ((dividend++) % divisor == 0));
        System.out.println(dividend + "可以整除" + divisor + "吗?" + ((dividend++) % divisor == 0));
        System.out.println(dividend + "可以整除" + divisor + "吗?" + ((dividend++) % divisor == 0));
        System.out.println(dividend + "可以整除" + divisor + "吗?" + ((dividend++) % divisor == 0));
        System.out.println(dividend + "可以整除" + divisor + "吗?" + ((dividend++) % divisor == 0));
        System.out.println(dividend + "可以整除" + divisor + "吗?" + ((dividend++) % divisor == 0));
        System.out.println(dividend + "可以整除" + divisor + "吗?" + ((dividend++) % divisor == 0));
        System.out.println(dividend + "可以整除" + divisor + "吗?" + ((dividend++) % divisor == 0));
        System.out.println(dividend + "可以整除" + divisor + "吗?" + ((dividend++) % divisor == 0));
        System.out.println(dividend + "可以整除" + divisor + "吗?" + ((dividend++) % divisor == 0));
        System.out.println(dividend + "可以整除" + divisor + "吗?" + ((dividend++) % divisor == 0));
        System.out.println(dividend + "可以整除" + divisor + "吗?" + ((dividend++) % divisor == 0));
        System.out.println(dividend + "可以整除" + divisor + "吗?" + ((dividend++) % divisor == 0));
        System.out.println(dividend + "可以整除" + divisor + "吗?" + ((dividend++) % divisor == 0));
        System.out.println(dividend + "可以整除" + divisor + "吗?" + ((dividend++) % divisor == 0));
        System.out.println(dividend + "可以整除" + divisor + "吗?" + ((dividend++) % divisor == 0));
        System.out.println(dividend + "可以整除" + divisor + "吗?" + ((dividend++) % divisor == 0));
        System.out.println(dividend + "可以整除" + divisor + "吗?" + ((dividend++) % divisor == 0));
        System.out.println(dividend + "可以整除" + divisor + "吗?" + ((dividend++) % divisor == 0));
        System.out.println(dividend + "可以整除" + divisor + "吗?" + ((dividend++) % divisor == 0));
        System.out.println(dividend + "可以整除" + divisor + "吗?" + ((dividend++) % divisor == 0));
        System.out.println(dividend + "可以整除" + divisor + "吗?" + ((dividend++) % divisor == 0));
        System.out.println(dividend + "可以整除" + divisor + "吗?" + ((dividend++) % divisor == 0));
        System.out.println(dividend + "可以整除" + divisor + "吗?" + ((dividend++) % divisor == 0));
        System.out.println(dividend + "可以整除" + divisor + "吗?" + ((dividend++) % divisor == 0));
        System.out.println(dividend + "可以整除" + divisor + "吗?" + ((dividend++) % divisor == 0));
        System.out.println(dividend + "可以整除" + divisor + "吗?" + ((dividend++) % divisor == 0));
        System.out.println(dividend + "可以整除" + divisor + "吗?" + ((dividend++) % divisor == 0));
        System.out.println(dividend + "可以整除" + divisor + "吗?" + ((dividend++) % divisor == 0));
        System.out.println(dividend + "可以整除" + divisor + "吗?" + ((dividend++) % divisor == 0));
        System.out.println(dividend + "可以整除" + divisor + "吗?" + ((dividend++) % divisor == 0));
        System.out.println(dividend + "可以整除" + divisor + "吗?" + ((dividend++) % divisor == 0));
        System.out.println(dividend + "可以整除" + divisor + "吗?" + ((dividend++) % divisor == 0));
        System.out.println(dividend + "可以整除" + divisor + "吗?" + ((dividend++) % divisor == 0));
        System.out.println(dividend + "可以整除" + divisor + "吗?" + ((dividend++) % divisor == 0));
        System.out.println(dividend + "可以整除" + divisor + "吗?" + ((dividend++) % divisor == 0));
        System.out.println(dividend + "可以整除" + divisor + "吗?" + ((dividend++) % divisor == 0));
        System.out.println(dividend + "可以整除" + divisor + "吗?" + ((dividend++) % divisor == 0));
        System.out.println(dividend + "可以整除" + divisor + "吗?" + ((dividend++) % divisor == 0));
        System.out.println(dividend + "可以整除" + divisor + "吗?" + ((dividend++) % divisor == 0));
        System.out.println(dividend + "可以整除" + divisor + "吗?" + ((dividend++) % divisor == 0));
        System.out.println(dividend + "可以整除" + divisor + "吗?" + ((dividend++) % divisor == 0));
        System.out.println(dividend + "可以整除" + divisor + "吗?" + ((dividend++) % divisor == 0));
        System.out.println(dividend + "可以整除" + divisor + "吗?" + ((dividend++) % divisor == 0));
        System.out.println(dividend + "可以整除" + divisor + "吗?" + ((dividend++) % divisor == 0));
        System.out.println(dividend + "可以整除" + divisor + "吗?" + ((dividend++) % divisor == 0));
        System.out.println(dividend + "可以整除" + divisor + "吗?" + ((dividend++) % divisor == 0));
        System.out.println(dividend + "可以整除" + divisor + "吗?" + ((dividend++) % divisor == 0));
        System.out.println(dividend + "可以整除" + divisor + "吗?" + ((dividend++) % divisor == 0));
        System.out.println(dividend + "可以整除" + divisor + "吗?" + ((dividend++) % divisor == 0));
        System.out.println(dividend + "可以整除" + divisor + "吗?" + ((dividend++) % divisor == 0));
        System.out.println(dividend + "可以整除" + divisor + "吗?" + ((dividend++) % divisor == 0));
        System.out.println(dividend + "可以整除" + divisor + "吗?" + ((dividend++) % divisor == 0));
        System.out.println(dividend + "可以整除" + divisor + "吗?" + ((dividend++) % divisor == 0));
        System.out.println(dividend + "可以整除" + divisor + "吗?" + ((dividend++) % divisor == 0));
        System.out.println(dividend + "可以整除" + divisor + "吗?" + ((dividend++) % divisor == 0));
        System.out.println(dividend + "可以整除" + divisor + "吗?" + ((dividend++) % divisor == 0));
        System.out.println(dividend + "可以整除" + divisor + "吗?" + ((dividend++) % divisor == 0));
        System.out.println(dividend + "可以整除" + divisor + "吗?" + ((dividend++) % divisor == 0));
        System.out.println(dividend + "可以整除" + divisor + "吗?" + ((dividend++) % divisor == 0));
        System.out.println(dividend + "可以整除" + divisor + "吗?" + ((dividend++) % divisor == 0));
        System.out.println(dividend + "可以整除" + divisor + "吗?" + ((dividend++) % divisor == 0));
        System.out.println(dividend + "可以整除" + divisor + "吗?" + ((dividend++) % divisor == 0));
        System.out.println(dividend + "可以整除" + divisor + "吗?" + ((dividend++) % divisor == 0));
        System.out.println(dividend + "可以整除" + divisor + "吗?" + ((dividend++) % divisor == 0));
        System.out.println(dividend + "可以整除" + divisor + "吗?" + ((dividend++) % divisor == 0));
        System.out.println(dividend + "可以整除" + divisor + "吗?" + ((dividend++) % divisor == 0));
        System.out.println(dividend + "可以整除" + divisor + "吗?" + ((dividend++) % divisor == 0));
        System.out.println(dividend + "可以整除" + divisor + "吗?" + ((dividend++) % divisor == 0));
        System.out.println(dividend + "可以整除" + divisor + "吗?" + ((dividend++) % divisor == 0));
        System.out.println(dividend + "可以整除" + divisor + "吗?" + ((dividend++) % divisor == 0));
    }
}
35可以整除9吗?false
36可以整除9吗?true
37可以整除9吗?false
38可以整除9吗?false
39可以整除9吗?false
40可以整除9吗?false
41可以整除9吗?false
42可以整除9吗?false
43可以整除9吗?false
44可以整除9吗?false
45可以整除9吗?true
46可以整除9吗?false
47可以整除9吗?false
48可以整除9吗?false
49可以整除9吗?false
50可以整除9吗?false
51可以整除9吗?false
52可以整除9吗?false
53可以整除9吗?false
54可以整除9吗?true
55可以整除9吗?false
56可以整除9吗?false
57可以整除9吗?false
58可以整除9吗?false
59可以整除9吗?false
60可以整除9吗?false
61可以整除9吗?false
62可以整除9吗?false
63可以整除9吗?true
64可以整除9吗?false
65可以整除9吗?false
66可以整除9吗?false
67可以整除9吗?false
68可以整除9吗?false
69可以整除9吗?false
70可以整除9吗?false
71可以整除9吗?false
72可以整除9吗?true
73可以整除9吗?false
74可以整除9吗?false
75可以整除9吗?false
76可以整除9吗?false
77可以整除9吗?false
78可以整除9吗?false
79可以整除9吗?false
80可以整除9吗?false
81可以整除9吗?true
82可以整除9吗?false
83可以整除9吗?false
84可以整除9吗?false
85可以整除9吗?false
86可以整除9吗?false
87可以整除9吗?false
88可以整除9吗?false
89可以整除9吗?false
90可以整除9吗?true
91可以整除9吗?false
92可以整除9吗?false
93可以整除9吗?false
94可以整除9吗?false
95可以整除9吗?false
96可以整除9吗?false
97可以整除9吗?false
98可以整除9吗?false
99可以整除9吗?true
100可以整除9吗?false
101可以整除9吗?false
102可以整除9吗?false
103可以整除9吗?false
104可以整除9吗?false
105可以整除9吗?false
106可以整除9吗?false
107可以整除9吗?false
108可以整除9吗?true
109可以整除9吗?false
110可以整除9吗?false
111可以整除9吗?false
112可以整除9吗?false
113可以整除9吗?false
114可以整除9吗?false
115可以整除9吗?false
116可以整除9吗?false
117可以整除9吗?true
118可以整除9吗?false
119可以整除9吗?false
120可以整除9吗?false
121可以整除9吗?false
122可以整除9吗?false
123可以整除9吗?false
124可以整除9吗?false
125可以整除9吗?false
126可以整除9吗?true
127可以整除9吗?false
128可以整除9吗?false
129可以整除9吗?false
130可以整除9吗?false
131可以整除9吗?false
132可以整除9吗?false
133可以整除9吗?false
134可以整除9吗?false

 

标签:divisor,++,08,数据类型,System,操作符,println,dividend,整除
来源: https://blog.51cto.com/u_13962552/2887434