codegurukool.com · Free coding tutorials & online compiler

Home › Java Tutorial › Java operators

Java operators

Arithmetic, assignment and comparison.

Arithmetic: + - * / %. Shortcuts: +=, ++, --. Comparison: == != < > <= >=. Logic: && (and), || (or), ! (not). % gives the remainder of a division.

Example code

public class Main {
  public static void main(String[] args) {
    int x = 7, y = 2;
    System.out.println(x + y);
    System.out.println(x / y);
    System.out.println(x % y);
    x += 3;
    x++;
    System.out.println(x);
    System.out.println(x > y && y > 0);
  }
}

Run this code in the online editor

← Java type castingJava strings →