Home / Programs / Unary Operator Example in Java
Programming Example

Unary Operator Example in Java

👁 2,142 Views
💻 Practical Program
📘 Step by Step Learning
Unary Operator Example in Java

Program Code

 public class OperatorExample {
public static void main(String args[])
   {  
    int x=10;  
    System.out.println(x++);//10 (11)  
    System.out.println(++x);//12  
    System.out.println(x--);//12 (11)  
    System.out.println(--x);//10  
   }
}  

Output

10
12
12
10

How to learn from this program

First read the algorithm, then study the program code line by line. After that, compare the code with the output and finally go through the explanation. This approach helps learners understand both the logic and the implementation properly.