Unary Operators in Java || lesson 12 || Java Programming || Learning Monkey ||

Publié le: 16 avril 2023
sur la chaîne: Learning Monkey
1,968
27

Unary Operators in Java
In this class, We discuss Unary Operators in Java.
The reader should have prior knowledge of arithmetic and logical operators. Click Here.
1) Postfix ++ and —
2) Prefix ++, –, -, ~, !
Example:
a=5;
System.out.println(a++);
System.out.println(a);
We write the ++ operator after the variable a. We call postfix increment.
First, the value of a is assigned then a is incremented.
The first display statement output is 5.
The second display statement will output 6.
Example 2:
a=5 b=6 c
c= a++ + b
System.out.println(c) will display 11
System.out.println(a) will display 6
Similarly, a– will decrement the value, i.e., a=a-1
Prefix increment
First, increment the value, then assign the value.
a=5 b=6 c
c= ++a + b
System.out.println(c) will display 12
System.out.println(a) will display 6
Unary Minus:
a= -2
The minus sign shown before two will give a negative 2.
Example 3:
a = 20 b = 10 c
c = -a + b
-a will take value -20.
System.out.println(c) will display -10.
Bitwise complement:
a=5, b
b = ~a;
System.out.println(b) will output -6.
5 in binary 000101
the bitwise complement will change the bit values from 1 to 0 and vice versa.
~a = 111010 is equal to -6 using a twos-complement representation.
Logical Not!
boolean x = true;
System.out.println(!x) will output false.

Link for playlists:
   / @learningmonkey  


Link for our website: https://learningmonkey.in

Follow us on Facebook @   / learningmonkey  

Follow us on Instagram @   / learningmonkey1  

Follow us on Twitter @   / _learningmonkey  

Mail us @ [email protected]


Sur cette page du site, vous pouvez voir la vidéo en ligne Unary Operators in Java || lesson 12 || Java Programming || Learning Monkey || durée heure minute seconde en bonne qualité , qui a été Téléchargé par l'utilisateur Learning Monkey 16 avril 2023, Partagez le lien avec vos amis et connaissances, sur youtube cette vidéo a déjà été regardée 1,968 fois et il a aimé 27 téléspectateurs. Bon visionnage!