B.Tech Students: Apply for Live Programming Internship C, C++, Java, Python ,Web page Designing, PHP Java Operators | Login Technologies

Java Operators

In Java, operators are special symbols or keywords used to perform operations on variables and values. Operators help in performing arithmetic calculations, comparisons, logical operations, and more.

Java में, operators विशेष प्रतीक या keywords होते हैं जो variables और मानों पर ऑपरेशन करने के लिए उपयोग किए जाते हैं। ऑपरेटर गणितीय गणना, तुलना, तार्किक ऑपरेशन आदि करने में मदद करते हैं।

We need operators to manipulate data and perform computations in programs efficiently.

हमें ऑपरेटर इसलिए चाहिए ताकि हम प्रोग्राम में डेटा को manipulate कर सकें और computation कर सकें।

Example 1: Addition (+)

public class Main {
    public static void main(String[] args) {
        int a = 5, b = 3;
System.out.println("Sum = " + (a + b));    }
}

Explanation (English): Adds two numbers.

व्याख्या (हिंदी): दो संख्याओं को जोड़ता है।

Output: Sum = 8


Example 2: Subtraction (-)

public class Main {
    public static void main(String[] args) {
        int a = 5, b = 3;
System.out.println("Difference = " + (a - b));    }
}

Explanation (English): Subtracts second number from first.

व्याख्या (हिंदी): दूसरी संख्या को पहली से घटाता है।

Output: Difference = 2


Example 3: Multiplication (*)

public class Main {
    public static void main(String[] args) {
        int a = 5, b = 3;
System.out.println("Product = " + (a * b));    }
}

Explanation (English): Multiplies two numbers.

व्याख्या (हिंदी): दो संख्याओं को गुणा करता है।

Output: Product = 15


Example 4: Division (/)

public class Main {
    public static void main(String[] args) {
        int a = 10, b = 2;
System.out.println("Quotient = " + (a / b));    }
}

Explanation (English): Divides first number by second.

व्याख्या (हिंदी): पहली संख्या को दूसरी से भाग देता है।

Output: Quotient = 5


Example 5: Modulus (%)

public class Main {
    public static void main(String[] args) {
        int a = 10, b = 3;
System.out.println("Remainder = " + (a % b));    }
}

Explanation (English): Gives remainder of division.

व्याख्या (हिंदी): भाग करने के बाद बचा हुआ शेषफल देता है।

Output: Remainder = 1


Example 6: Greater Than (>)

public class Main {
    public static void main(String[] args) {
        int a = 5, b = 3;
System.out.println("a > b: " + (a > b));    }
}

Explanation (English): Checks if a is greater than b.

व्याख्या (हिंदी): जांचता है कि a, b से बड़ा है या नहीं।

Output: a > b: true


Example 7: Less Than (<)

public class Main {
    public static void main(String[] args) {
        int a = 2, b = 4;
System.out.println("a < b: " + (a < b));    }
}

Explanation (English): Checks if a is less than b.

व्याख्या (हिंदी): जांचता है कि a, b से छोटा है या नहीं।

Output: a < b: true


Example 8: Logical AND (&&)

public class Main {
    public static void main(String[] args) {
        boolean a = true, b = false;
System.out.println("a && b: " + (a && b));    }
}

Explanation (English): Returns true if both a and b are true.

व्याख्या (हिंदी): दोनों सही होने पर true देता है।

Output: a && b: false


Example 9: Logical OR (||)

public class Main {
    public static void main(String[] args) {
        boolean a = true, b = false;
System.out.println("a || b: " + (a || b));    }
}

Explanation (English): Returns true if at least one is true.

व्याख्या (हिंदी): कम से कम एक सही हो तो true देता है।

Output: a || b: true


Example 10: Assignment (=)

public class Main {
    public static void main(String[] args) {
        int a;
a = 10;
System.out.println("a = " + a);    }
}

Explanation (English): Assigns value 10 to variable a.

व्याख्या (हिंदी): variable a को 10 मान असाइन करता है।

Output: a = 10