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

Oldest comments (0)

πŸ” If you came here from Google, why not take a look at some of our top posts?