DEV Community 👩‍💻👨‍💻

Cover image for Operators in Java
Brain CodeDesign
Brain CodeDesign

Posted on

Operators in Java

Basic stands everywhere so in programming too operators are the fundamentals of any programming language so in this blog I'll write about the operators in Java
So what basically operators are?
"Operators are used to perform operations on variables and values"

Arthmetic operator
int num1 = 10;

    int num2 = 20;
    System.out.println("the value of num1 + num2 is");
    System.out.println(num1 + num2);
    System.out.println("the value of num1 - num2 is");
    System.out.println(num1 - num2);
    System.out.println("the value of num1 * num2 is");
    System.out.println(num1 * num2);
    System.out.println("the value of num1 / num2 is");
    System.out.println(num1 / num2);
    System.out.println("the value of num1 % num2 is");
    System.out.println(num1 % num2);
Enter fullscreen mode Exit fullscreen mode

Assignment operator
int num1 = 10;
int num2 = 20;
num2 = num1;

    System.out.println("= Output: "+num2);

    num2 += num1;

    System.out.println("+= Output: "+num2);
    num2 -= num1;
    System.out.println("-= Output: "+num2);
    num2 *= num1;
    System.out.println("*= Output: "+num2);
    num2 /= num1;
    System.out.println("/= Output: "+num2);
    num2 %= num1;
    System.out.println("%= Output: "+num2);
Enter fullscreen mode Exit fullscreen mode

Logical operator
Int a=9;
Int b=11;
int c=20;

    System.out.println(a<b&a<c);
    System.out.println(a>b||a<c)
    System.out.println(a>b|a<c);
    System.out.println(a>b||a++<c);
    System.out.println(a);
    System.out.println(a>b|a++<c);
    System.out.println(a);
Enter fullscreen mode Exit fullscreen mode

Comparison or rational operator
Int a=9;
Int b=11;
int c=20;

    System.out.println("a is "+  a + " and b is " + b);

    // == operator
    System.out.println(a == b);  // false

    // != operator
    System.out.println(a != b);  // true

    // > operator
    System.out.println(a > b);  // false

    // < operator
    System.out.println(a < b);  // true

    // >= operator
    System.out.println(a >= b);  // false

    // <= operator
    System.out.println(a <= b);  // true
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

DEV

Thank you.

 
Thanks for visiting DEV, we’ve worked really hard to cultivate this great community and would love to have you join us. If you’d like to create an account, you can sign up here.