A. Arithmetic Operators
Operator_Arithmetic.java
public class Operator_Arithmetic {
int a;
int b;
int c;
Operator_Arithmetic() {
a = 10;
b = 2;
}
void add() {
c = a + b;
System.out.println("The Addition is : " + c);
}
void sub() {
c = a - b;
System.out.println("The Subtraction is : " + c);
}
void multi() {
c = a * b;
System.out.println("The Multiplication is : " + c);
}
void div() {
c = a / b;
System.out.println("The Division is : " + c);
}
void mod() {
c = a % b;
System.out.println("The Modulus is : " + c);
}
void inc() {
c = ++a;
System.out.println("The Increment is : " + c);
}
void dec() {
c = --a;
System.out.println("The Decrement is : " + c);
}
}
class MainClass {
public static void main (String args[]) {
Operator_Arithmetic obj = new Operator_Arithmetic();
obj.add();
obj.sub();
obj.multi();
obj.div();
obj.mod();
obj.inc();
obj.dec();
}
}
Sample Output
The Addition is : 12
The Subtraction is : 8
The Multiplication is : 20
The Division is : 5
The Modulus is : 0
The Increment is : 11
The Decrement is : 10
B. Relational Operators
Operator_Relation.java
public class Operator_Relation {
int a = 10;
void relation() {
if(a==10) {
System.out.println("Equal Operator : Verified");
}
if(a!=20) {
System.out.println("Not Equal Operator : Verified");
}
if(a>5) {
System.out.println("Greaterthan Operator : Verified");
}
if(a<15 span="">15>
System.out.println("Lessthan Operator : Verified");
}
if(a>=9) {
System.out.println("Greaterthan or Equal Operator : Verified");
}
if(a<=11) {
System.out.println("Lessthan or Equal Operator : Verified");
}
}
}
class MainClass {
public static void main (String args[]) {
Operator_Relation obj = new Operator_Relation();
obj.relation();
}
}
Sample Output
Equal Operator : Verified
Not Equal Operator : Verified
Greaterthan Operator : Verified
Lessthan Operator : Verified
Greaterthan or Equal Operator : Verified
Lessthan or Equal Operator : Verified
C. Bitwise Operators
Operator_Bitwise.java
public class Operator_Bitwise {
public static void main(String args[]) {
int a = 60;
int b = 30;
int c;
System.out.println("Bitwise Operators");
c = ~a;
System.out.println("\n~ a :" + c);
c = a & b;
System.out.println("\na & b : " + c);
c = a | b;
System.out.println("a | b : " + c);
c = a ^ b;
System.out.println("a ^ b : " + c);
c = a << 2;
System.out.println("\na << 2 : " + c);
c = a >> 2;
System.out.println("a >> 2 : " + c);
c = a >>> 2;
System.out.println("\na >>> 2 : " + c);
}
}
Sample Output
Bitwise Operators
~ a :-61
a & b : 28
a | b : 62
a ^ b : 34
a << 2 : 240
a >> 2 : 15
a >>> 2 : 15
D. Logical Operators
Operator_Logical.java
public class Operator_Logical {
public static void main(String args[]) {
boolean a = true;
boolean b = false;
boolean c;
System.out.println("Logical Operators");
c = a && b;
System.out.println("\na && b :" + c);
c = a || b;
System.out.println("a || b : " + c);
c = !(a && b);
System.out.println("\n!(a && b) : " + c);
c = !(a || b);
System.out.println("!(a || b) : " + c);
}
}
Sample Output
Logical Operators
a && b :false
a || b : true
!(a && b) : true
!(a || b) : false
E. Assignment Operators
Operator_Assignment.java
public class Operator_Assignment {
public static void main(String args[]) {
int x = 10;
int y = 20;
System.out.println("Assignment Operators");
x += y;
System.out.println("\nThe addition is : " + x);
x -= y;
System.out.println("The subtraction is : " + x);
x *= y;
System.out.println("The multiplication is : " + x);
x /= y;
System.out.println("The division is : " + x);
x %= y;
System.out.println("The remainder is : " + x);
x &= y;
System.out.println("The result of AND operation : " + x);
x |= y;
System.out.println("The result of Bitwise inclusive OR operation : " + x);
x <<= y;
System.out.println("The result of Signed left shift operation : " + x);
}
}
Sample Output
Assignment Operators
The addition is : 30
The subtraction is : 10
The multiplication is : 200
The division is : 10
The remainder is : 10
The result of AND operation : 0
The result of Bitwise inclusive OR operation : 20
The result of Signed left shift operation : 20971520
F. Conditional Operator
Operator_Conditional.java
public class Operator_Conditional {
public static void main(String args[]) {
int a = 10 , b;
System.out.println("Conditional Operators");
b = (a == 1) ? 100 : 200;
System.out.println( "\nValue of b is : " + b );
b = (a == 10) ? 100 : 200;
System.out.println( "Value of b is : " + b );
}
}
Sample Output
Conditional Operators
Value of b is : 200
Value of b is : 100
|
know more about WebDriver, TestNG, Jenkins, Framework, Page Object Model, Cucumber, Selenium Grid
Java Operators
Subscribe to:
Posts (Atom)
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.