-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathIncDecOperator.java
More file actions
62 lines (53 loc) · 1.61 KB
/
IncDecOperator.java
File metadata and controls
62 lines (53 loc) · 1.61 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
public class IncDecOperator
{
public static void main(String args[])
{
int x=10;
System.out.println("initial value of x= "+x); //10
char ch='a';
System.out.println("initial value of ch= "+ch); //a
ch++;
System.out.println("final value of ch= "+ch); //b
double d=10.5;
System.out.println("initial value of d= "+d); //10.5
d++;
System.out.println("final value of d= "+d); //11.5
boolean b=true;
System.out.println("initial value of b= "+b); //true
//b++; operator ++ can't be applied to boolean
//System.out.println("final value of b= "+b);
final int z=10;
//z++; can't assign a value to final variable z
//System.out.println("initial value of z= "+z);
int y=++x;
//int y=++10; unexpected type
//int y=++(++x); nesting of increment operator not allowed
System.out.println("value of y= "+y); //11
System.out.println("final value of x= "+x); //11
x=10;
System.out.println("initial value of x= "+x); //10
y=x++;
System.out.println("value of y= "+y); //10
System.out.println("final value of x= "+x); //11
x=10;
System.out.println("initial value of x= "+x); //10
y=--x;
System.out.println("value of y= "+y); //9
System.out.println("final value of x= "+x); //9
x=10;
System.out.println("initial value of x= "+x); //10
y=x--;
System.out.println("value of y= "+y); //10
System.out.println("final value of x= "+x); //9
byte a1=10;
byte b1=20;
//byte c=a1+b1;max(int,byte,byte)
byte c=(byte)(a1+b1);
System.out.println("value of c= "+c); //30
byte a2=20;
byte b2=20;
//b2=b2+1;max(int,byte,int)
b2=(byte)(b2+1);
System.out.println("value of c= "+c);
}
}