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);
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);
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);
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
Top comments (0)