Home / Programs / Java Unary Operator Example: ~ and !
Programming Example

Java Unary Operator Example: ~ and !

👁 5,290 Views
💻 Practical Program
📘 Step by Step Learning
Java Unary Operator Example: ~ and !

Program Code

public class OperatorExample {
    public static void main(String args[])
    {  
    int a=10;  
    int b=-10;  
    boolean c=true;  
    boolean d=false;  
    System.out.println(~a);  
    System.out.println(~b);  
    System.out.println(!c); 
    System.out.println(!d); 
    }
} 

Output

22
21

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.