If tutorials available on this website are helpful for you, please whitelist this website in your ad blocker😭 or Donate to help us ❤️ pay for the web hosting to keep the website running.
Operator एक symbol होते हैं , जो process / operation represent करते हैं करते हैं , या हम कह सकते हैं की Operators को कोई process / या operation को perform करने के लिए use करते हैं।
For Example -
class Operators
{
public static void main(String[] args)
{
int a = 7;
int b = 89;
// here = is a assignment operator.
System.out.println(a+b);
// here + is arithmetic operator.
}
}
Output
96
ऊपर दिए गए example में आप देखा सकते हैं कि + (plus sign)
Operator define की गयी दो values को add रहा है।
●●●
इसी तरह से Java में different - different action perform करने के लिए different - different Operators है । Java में normally use होने वाले Operators कुछ इस प्रकार हैं -
Arithmetic Operators
Assignment Operators
Comparison / Relational Operators
Logical Operators
Increment / Decrement Operator
●●●
Arithmetic Operators simple calculation में use होने wale Operators होते हैं जैसे Addition , Subtraction etc.
Operator | Name | Example | Explanation |
---|---|---|---|
+ | Addition | x+y | ( + ) plus operator uses to add two or more numbers / values |
- | Subtraction | x-y | ( - ) minus operator uses to substract one numbers / values from another numbers / values or finds the difference |
/ | Division | x / y | quotient of x and y with decimal point. |
* | multiplication | x * y | product of x and y |
% | Modulus | x % y | remainder of operands |
Assignment Operator को equals to =
से represent करते हैं , जो कि value को किसी variable में assign करने के लिए use किया जाता है।
हालाँकि इसे Arithmetic Operators के साथ भी use करते हैं। नीचे दिए गए Example में आप देख सकते हैं।
Operator | Name | Example | Explanation |
---|---|---|---|
= | Assign | x = y | value of y assigned to x |
!= | Assign | x = y | value of y assigned to x |
+= | Addition then Assign | x += y | First add and assign it to x. (It is same as x = x+y ) |
- = | Subtract then Assign | x -= y | get the difference and assign it to x. (It is same as x = x-y ) |
/ = | Divide then assign quotient | x /= y | quotient of x and y then assign it to x . (It is same as x = x/y ) |
* = | Multiplication then assign the product | x * =y | product of x and y then assign it to x. (It is same as x = x*y ) |
% = | Divide then assign remainder | x %= y | remainder of operands then assign it to x. (It is same as x = x+%y ) |
class AssignmentOperator
{
public static void main(String[] args)
{
// add then assign.
int a = 90;
a += 10;
System.out.println(a);
// devide 100 by 2 and assign.
a /= 2;
System.out.println("Quotient : "+ a);
// get module deviding 50 by 11 then assign.
a %= 11;
System.out.println("Modulas : "+ a);
}
}
Output
100 quotient : 50 Modulas : 6
●●●
Incrementing-Decrementing Operators को किसी variable को 1 से increase
या decrease
करने के लिए use किया जाता है। हालाँकि इसमें Addition और Subtraction operation ही होते हैं , इसलिए इसमें ( ++ ) या ( -- ) sign ही use होते हैं।
नीचे table में आप देख सकते हैं किसा तरह से
इन्हे use करते हैं और क्या Output generate हैं।
Operator | Name | Explanation |
---|---|---|
++a | Pre Increment | first increment by 1 then return the value of a |
a++ | post Increment | first return the value of a then increment by 1. |
--a | Pre Decrement | first decrement by 1 then return the value of a |
a-- | Post Decrement | first return the value of a then decrement by 1. |
class IncDecOperator
{
public static void main(String[] args)
{
int a = 90;
System.out.println("Initial value : "+a);
// increment by 1
a++;
System.out.println("After increment : "+a);
// decrement by 1
a--;
System.out.println("After decrement : "+a);
}
}
Output
Initial value : 90 After increment : 91 After decrement : 90
●●●
Comparison Operators दी हुई दो values को compare करके condition के according boolean value true / false
value return करते हैं।
Java में Comparison Operators को कुछ इस तरह से use कर सकते हैं।
Operator | Name | Example | Explanation |
---|---|---|---|
== | Equal | x = = y | checks if x is equal to y. |
!= | Not equal | x !=y | checks if x is not equal to y. |
< | Less than | x < y | checks if x is less than y. |
> | Greater than | x > y | checks if x is greater than y. |
<= | Less than or equal | x <= y | checks either x is less than or equal to y. |
>= | Greater than or equal | x >= y | checks either x is greater than or equal to y. |
●●●
Logical Operators , एक या एक से अधिक expression के according Boolean value return करते हैं। जैसे -
Operator | Name | Example | Explanation |
---|---|---|---|
&& | And | x && y | returns True if Both operands (x and y) are true; |
! | Not | !x | Returns True if x is not true; |
|| | Or | x || y | returns True if either x or y is true; |
●●●
I Hope, अब आपको Java में operators के बारे में अच्छे से समझ आ गया होगा।