Page 30 - CTS - CSA TP - Volume 2
P. 30
COMPUTER SOFTWARE APPLICATION - CITS
5 Pre-decrement (--x):
• System.out.println(--x); is a pre-decrement operation. It decrements the value of x by 1 and then prints the
updated value.
• The output is 10 because x was decremented in the previous step.
Output:
TASK 2: Java Unary Operator Example 2: ++ and --
CODE:
public class OperatorExample2{
public static void main(String args[]){
int a=10;
int b=10;
System.out.println(a++ + ++a);//10+12=22
System.out.println(b++ + b++);//10+11=21
}}
Output :
Explanation:
• The program illustrates the behavior of post-increment and pre-increment operators in expressions.
• Post-increment (a++ or b++) evaluates to the current value before the increment, while pre-increment (++a)
evaluates to the updated value after the increment.
• The output demonstrates the results of the two expressions involving increment operations.
TASK 3: Java Unary Operator Example: ~ and !
public class OperatorExample3{
public static void main(String args[]){
int a=10;
int b=-10;
boolean c=true;
15
CITS : IT & ITES - Computer Software Application - Exercise 82