Java Unary Operator Negating Example


Program
public class UnaryOperator{ public static void main(String args[]){ int x=-2; int y=2; System.out.println(~x);//1 //(-2,-1,0,1 So 1 will be output , negating of negative value start from 0) System.out.println(~y); //(2,1,0,-1,-2,-3 So 1 will be output , negating of positive value start from -1) }}
Input
Output