operators in java

List of Operators in Java

  • Arithmetic Operators
          Addition        +
          Subtraction   -
          Multiplication *
          Division         /
          Remainder(Module)    %
  • Relational Operators
  • Logical Operators
  • Bitwise Operators
  • Assignment Operators
  • Ternary or Conditional Operators

 

Adition operator :-
package seleniumtool.com;

public class AddingNumbers {

    public static void main(String[] args) {
        int i=9;
        int j=3;
        int result = i+j;
        System.out.println("Result is :" + result);
    }

}

Result is :12

Subtraction in Java

package seleniumtool.com;

public class Subtraction {

    public static void main(String[] args) {
        int i= 20;
        int j= 10;
        int k= i-j;
        System.out.println("Result=" + k);
    }

}

Result=10

Multiplication in Java

package seleniumtool.com;

public class Multiplication {

    public static void main(String[] args) {
        int i= 2;
        int j= 3;
        int k= i*j;
        System.out.println("Result=" + k);
    }

}

Result=6

Division in java

package seleniumtool.com;

public class Division {

    public static void main(String[] args) {
        int i= 12;
        int j= 3;
        int k= i/j;
        System.out.println("Result=" + k);
    }

}

Result=4

 

Modulus operator in Java

package seleniumtool.com;

public class Modulus {

    public static void main(String[] args) {
        float i= 10f;
        float j= 3f;
        float k= i/j%100;
        System.out.println("Result=" + k);
    }

}

Result=3.3333333

 

Comments