Java Reference
In-Depth Information
public static void main (String args[]) {
int p = 1;
int q = 2;
int r;
int s;
r = ++q;
s =p++;
System.out.println(“p = “ + p);
System.out.println(“q= “ + q);
System.out.println(“r = “ + r);
System.out.println(“s = “ +s);
The output of this program follows:
p = 2
q = 3
r= 4
s = 1
If you are well understood with the above program,, then you please try decre-
ment operator yourself. It works in the same way as increment with a single dif-
ference that it decreases value by 1 instead of increasing.
Conditional Operator
Ternary operator is a very important conditional operator provided by Java. It has the con-
ditional statements of following form:
Expression 1 ? expression 2 : expression 3
In the above conditional statement, firstly expression 1 is calculated and the result of the
conditional expression depends on its result whether it is true or false.
Search WWH ::

Custom Search