what is the and operator in java code example

Example 1: Operators in java

// example on ternary operator in java
public class TernaryOperatorDemo
{
   public static void main(String[] args)
   {
      int a = 50, b = 500, bigger;
      System.out.println("First number: " + a);
      System.out.println("Second number: " + b);
      bigger = (a > b) ? a : b;
      System.out.println("Bigger number is = " + bigger);
   }
}

Example 2: Operators in java

// Arithmetic operators in java
public class ArithmeticOperatorDemo
{
   public static void main(String[] args)
   {
      int i = 25;
      int j = 5;
      System.out.println(i + j);
      System.out.println(i - j);
      System.out.println(i * j);
      System.out.println(i / j);
      System.out.println(i % j);
   }
}

Example 3: Operators in java

// java assignment operator with examples
public class AssignmentOperatorDemo
{
   public static void main(String[] args)
   {
      int numOne = 60;
      int numTwo = 30;
      numTwo += numOne;
      System.out.println("(+=) : " + numTwo);
      numTwo -= numOne;
      System.out.println("(-=) : " + numTwo);
      numTwo *= numOne;
      System.out.println("(*=) : " + numTwo);
      numTwo /= numOne;
      System.out.println("(/=) : " + numTwo);
      numTwo %= numOne;
      System.out.println("(%=) : " + numTwo);
   }
}

Example 4: Operators in java

// java unary (~) operator
public class JavaUnaryOperator
{
   public static void main(String[] args)
   {
      int a = 8, b = -4;
      System.out.println("a = " + a);
      System.out.println("b = " + b);
      System.out.println(a + " java bitwise complement is = " + ~a);
      System.out.println(b + " java bitwise complement ia = " + ~b);
   }
}

Tags:

Java Example