Hello friends..... Today I will write about Operatos in Java in the best way so that you can understand this very well. Q.what are the operators? Ans.Operators are special symbols, Which applied on single or multiple operands and return some result. Q.what are the types of Operators in Java? Ans.there are 3 types of Operators in java. 1.Unary 2.Binary link:http://spojdev.blogspot.in/2016/06/java-binary-operators-tutorial.html 3.Ternary link:http://spojdev.blogspot.in/2016/06/java-ternary-operator.html
Unary Operators Definition:operators which are applied on single operand. Types: 1.Postfix expr example: expr++,expr-- 2.Prefix expr example: ++expr,--expr 3.logical not example: !(expr) 4.bitwise not example: ~ 5.sign indicator example: +expr, -expr Demo: public class Unary{ public static void main(String args[]){ int x=5; //postfix expr System.out.println("x++ is:"+ x++); System.out.println("x-- is:"+ x--); System.out.println("x is:"+ x); //prefix expr System.out.println("++x is:"+ ++x); System.out.println("--x is:"+ --x); System.out.println("x is:"+ x); //logical not if(!(x==5)){ System.out.println("x is not equal to 5"); } else{ System.out.println("x is equal to 5"); } //bitwise not System.out.println("bitwise not of aa is :" + ~x); //sign indicator System.out.println("its very simple like " + -x); System.out.println("its very simple like " + +x); } } ouput of demo is: x++ is:5 x-- is:6 x is:5 ++x is:6 --x is:5 x is:5 x is equal to 5 bitwise not of aa is :-6 its very simple like -5 its very simple like 5
No comments:
Post a Comment