-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIncrementAndDecrementOperators.java
More file actions
67 lines (52 loc) · 1.19 KB
/
Copy pathIncrementAndDecrementOperators.java
File metadata and controls
67 lines (52 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package JavaSessions;
public class IncrementAndDecrementOperators {
public static void main(String[] args) {
//1. ++ --> increment by 1
//post increment
//first: assign to left hand side operator
//second: then you increase the value
int a = 1;
int b = a++;
System.out.println(a);//2
System.out.println(b);//1
int c = -99;
int d = c++;
System.out.println(c);//-98
System.out.println(d);//-99
//pre increment: ++
int h = 1;
int g = ++h;
System.out.println(h);//2
System.out.println(g);//2
int p = -97;
int q = ++p;
System.out.println(p);//-96
System.out.println(q);//-96
//post decrement: --
int r = 2;
int s = r--;
System.out.println(r);//1
System.out.println(s);//2
int x = -999;
int y = x--;
System.out.println(x);//-1000
System.out.println(y);//-999
//pre decrement: --
int u = 2;
int v = --u;
System.out.println(u);//1
System.out.println(v);//1
int n = 2;
System.out.println(n++);
System.out.println(n);
int m = 3;
System.out.println(++m);
int f = 'a';
int w = 'b';
System.out.println(f+w);
char b1 = 'a';
char b2 = 'b';
System.out.println(b1+""+b2);
System.out.println(""+b1+b2);
}
}