नमस्कार दोस्तो आज इस Article में जानेंगे Java Operators in hindi | (जावा ऑपरेटर्स क्या हैं) / Java Operators कितने प्रकार के होते हैं ?
Java Operators का उपयोग हम variables पर operations perform करने के लिए करते हैं। हर एक data type पर अलग अलग operations perform किये जाते हैं। इसलिए operators भी अलग अलग यूज़ होते हैं।
Java Arithmetic Operators :
Java Arithmetic Operators in hindi :
Operators | Explaination |
---|---|
+ (Addition) | ये दो Operands को add करता है | |
- (Subtraction) | ये right operand से left operand को निकाल देता है | |
* (Multiplication) | ये दो Operands को multiply करता है | |
/ (Division) | ये right operand द्वारा left operand को divide करता है | |
% (Modulus) | ये right operand द्वारा left operand को divide करके remainder निकालता है | |
Example of Java Arithmetic Operators :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | //Sample.java class Sample{ public static void main(String args[]) { int a = 10, b = 5, c; c=a + b; System.out.println("Addition of a and b is " + c); c=a - b; System.out.println("Subtraction of a and b is " + c); c=a * b; System.out.println("Multiplication of a and b is " + c); c=a / b; System.out.println("Division of a and b is " + c); c=a % b; System.out.println("Remainder of a and b is " + c); } } |
Output :
1 2 3 4 5 | Addition of a and b is 15 Subtraction of a and b is 5 Multiplication of a and b is 50 Division of a and b is 2 Remainder of a and b is 0 |
Relational Operators :
Java Relational Operators in hindi :
Operators | Explaination |
---|---|
<</strong> (less than) | एक Operand की value दूसरे Operand से कम हो तो ये true return करता है | for eg. num1=5; num2=6; num1 < num2 |
> (greater than) | एक Operand की value दूसरे Operand से ज्यादा हो तो ये true return करता है | for eg. num1=6; num2=5; num1 > num2 |
<= (less than or equal to) | एक Operand की value दूसरे Operand से कम हो या बराबर (equal) हो तो ये true return करता है | for eg. num1=5; num2=5; num1 <= num2 |
>= (greater than or equal to) | एक Operand की value दूसरे Operand से ज्यादा हो या बराबर (equal) हो तो ये true return करता है | for eg. num1=5; num2=5; num1 >= num2 |
== (equal to) | दो Operands जब बराबर(equal) होते है, तब ये true return करता है | |
!= (not equal to) | दो Operands जब एक-दूसरे से अलग होते है, तब ये true return करता है | |
Example of Relational Operators :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | //Sample.java class Sample{ public static void main(String args[]){ int a = 6, b = 5; if(a < b){ System.out.println("a is less than b"); } else{ System.out.println("a is greater than b"); } if(a <= b){ System.out.println("a is less than b"); } else{ System.out.println("a is greater than b"); } if(a > b){ System.out.println("a is greater than b"); } else{ System.out.println("a is less than b"); } if(a >= b){ System.out.println("a is greater than b"); } else{ System.out.println("a is less than b"); } if(a == b){ System.out.println("a is equal to b"); } else{ System.out.println("a is not equal to b"); } } } |
Output :
1 2 3 4 5 | a is greater than b a is greater than b a is greater than b a is greater than b a is not equal to b |
Logical Operators :
Java logical operators in hindi :
Operators | Explaination |
---|---|
&& (logical &&) | अगर दोनों conditions true हो तो ये true return करेगा | for eg. (5<6) && (6>5) |
|| (logical OR) | अगर दोनों में से एक भी true है , तो ये true return करेगा | for eg. (5<6) || (6>5) |
! (logical not) | अगर condition true हो तो ये उसे false कर देता है | for eg. !((5<6) && (6>5)) !((5<6) || (6>5)) |
Example of Java logical operators :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | //Sample.java class Sample{ public static void main(String args[]){ if((5 < 6) && (6 > 5)){ System.out.println("Condition is true."); } else{ System.out.println("Condition is false."); } if((5 < 6) || (6 > 5)){ System.out.println("Condition is true."); } else{ System.out.println("Condition is false."); } if(!((5 < 6) && (5 > 6))){ System.out.println("Condition is true."); } else{ System.out.println("Condition is false."); } } } |
Output :
1 2 3 | Condition is true. Condition is true. Condition is true. |
Bitwise Operators :
Bitwise Operators in hindi
यह Bit पर work करता है तथा Bit By Bit perform किया जाता है |
माना कि a के पास 60 है और b के पास 13 है तो ,
a = 0011 1100
b = 0000 1101
Operator | Value | Operation |
a&b | 0000 1100 | and |
a|b | 0011 1101 | or |
a^b | 0011 0001 | xor |
~a | 1100 0011 | compliment |
Binary Left Shift( << ) and Right Shift( >> )
- Left Shift(<<) for e.g. a=20; /* 0001 0100 */ a << 2 में numeric value के binary value में हर binary number को 2 binary numbers left side से shift करता है | for e.g.a=20; /* 0001 0100 */ तो इसका 0101 0000 मतलब 80 हो जायेगा |
- Right Shift(>>) for e.g. a=20; /* 0001 0100 */ ये Left shift से बिलकुल उलट है | Right Shift a>> 2 में numeric value के binary value में हर binary number को 2 binary numbers right side से shift करता है | for e.g.a=20; /* 0001 0100 */ तो इसका 0000 0101 मतलब 5 हो जायेगा |
Assignment Operators :
Java Assignment Operators in hindi
Assignment Operators ग्यारह प्रकार के होते है |
- Assignment Operator (=)
- Add Assignment Operator (+=)
- Subtract Assignment Operator (-=)
- Multiply Assignment Operator (*=)
- Divide Assignment Operator (/=)
- Modulus Assignment Operator (%=)
- Bitwise AND Assignment Operator (&=)
- Bitwise OR Assignment Operator (|=)
- Bitwise XOR Assignment Operator (^=)
- Left Shift Assignment Operator (<<=)
- Right Shift Assignment Operator (>>=)
Operators | Examples |
---|---|
= (assignment) | c = a + b |
+= (add assignment) | c += a same as c = c + a |
-= (subtract assignment) | c -= a same as c = c - a |
*= (multiply assignment) | c *= a same as c = c * a |
/= (divide assignment) | c /= a same as c = c / a |
%= (modulus assignment) | c %= a same as c = c % a |
&= (AND assignment) | c &= a same as c = c & a |
|= (OR assignment) | c |= a same as c = c | a |
^= (XOR assignment) | c ^= a same as c = c ^ a |
<<= (Left Shift assignment) | c <<= a same as c = c << a |
>>= (Right Shift assignment) | c >>= a same as c = c >> a |
Example of Assignment Operators :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | class Sample{ public static void main(String args[]){ int a=20, b=12; b = a + b; System.out.println("value of b is " + b); b += a; System.out.println("value of b is " + b); b -= a; System.out.println("value of b is " + b); b *= a; System.out.println("value of b is " + b); b /= a; System.out.println("value of b is " + b); b %= a; System.out.println("value of b is " + b); b &= 2; System.out.println("value of b is " + b); b |= 2; System.out.println("value of b is " + b); b ^= 2; System.out.println("value of b is " + b); b <<= 2; System.out.println("value of b is " + b); b >>= 2; System.out.println("value of b is " + b); } } |
1 2 3 4 5 6 7 8 9 10 11 | value of b is 32 value of b is 52 value of b is 32 value of b is 640 value of b is 32 value of b is 12 value of b is 0 value of b is 2 value of b is 0 value of b is 0 value of b is 0 |
Java - Increment And Decrement :
- Increment Operator (++) ये variable की value 1 से बढ़ा देता है |
- Decrement Operator (--) ये variable की value 1 से घटा देता है |
Operators | Same as |
---|---|
++a (Increment Prefix) | a = a + 1 |
--a (Decrement Prefix) | a = a - 1 |
a++ (Increment Postfix) | |
a-- (Decrement Postfix) |
Example of Java - Increment And Decrement :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | class Sample{ public static void main(String args[]){ int a=20; System.out.println("Print Value with prefix : " + ++a); // increase value with increment prefix System.out.println("Value of a : " + a); System.out.println("Print Value with prefix : " + --a); // decrease value with decrement prefix System.out.println("Value of a : " + a); System.out.println("Print Value with postfix : " + a++); // increase value with increment postfix System.out.println("Value of a : " + a); System.out.println("Print Value with postfix : " + a--); // decrease value with decrement postfix System.out.println("Value of a : " + a); } } |
Output :
1 2 3 4 5 6 7 8 | Print Value with prefix : 21 Value of a : 21 Print Value with prefix : 20 Value of a : 20 Print Value with postfix : 20 Value of a : 21 Print Value with postfix : 21 Value of a : 20 |
Java - Conditional Operator :
Java - Conditional Operator in hindi
- Conditional Operator में तीन Expressions होते है |
- Conditional Operator को Ternary Operator भी कहते है |
- Conditional Operator में अगर पहला expression true होता है, तो वो दूसरा expression output में print करता है |
- अगर Conditional Operator में पहला expression false होता है, तो वो तीसरा expression output में print करता है |
Syntax for Conditional / Ternary Operator
expression1 ? expression 2 : expression 3Example :
1 2 3 4 5 6 7 8 9 10 11 | class Sample{ public static void main(String args[]){ int a = 100, b ; b = ( a == 100 ? 2 : 0 ) ; System.out.println("Value of a is " + a); System.out.println("Value of b is " + b); } } |
Output :
1 2 | Value of a is 100 Value of b is 2 |
अगर आपको यह पोस्ट 📑 पसंद आई हो तो अपने मित्रों के साथ जरूर शेयर करें। धन्यवाद !
Tags:
Java