Expressions

These are simple “Expression” examples.

First a “plus/minus one” example.

public class PlusMinusOne {
 
  public static void main(String[] args ) {
    int a = 4;
    int b = 5;
 
    System.out.println(++a);
    System.out.println(b--);
    System.out.println(a++);
    System.out.println(--b);
  }
}

Divide with a leftover.
public class Divide{
 
  public static void main(String[] args ) {
  int a=9;
  int b=2;
  int quotient;
  int rest;
 
  quotient =a/b;
  rest = a % b;
 
  System.out.println("a/b= "+quotient + " Rest: "+rest);
  }
}

Complex math tasks.

public class ComplexMath {
 
  public static void main(String[] args ) {
 
  double a = 3;
  double c=12/(8*a*a);
 
  System.out.println(+c);
 
  double d = 2;
  double j = ((3*d*d*d*d)-(2*d*d*d))+(d-2);
 
  System.out.println(+j);
 
  double y = 4;
  double x = 3;
  double u= x*((2*x)+(3*y))/((3*x)+y)*((2*x)-(2*y));
 
  System.out.println(+u);
 
  }
}

Compare with equal, lower, greater…

public class Equal {
 
  public static void main(String[] args) {
 
    int a = 4;
    int b = 5;
    boolean lower ,lowerequal;
    boolean greater, greaterequal;
    boolean equal, notequal;
 
 
    lower = (a < b);
    lowerequal = (a <= b);
    greater = (a > b);
    greaterequal = (a >= b);
    equal = (a == b);
    notequal = (a != b);
 
    System.out.println (a + " < " +b + " : "+ lower);
    System.out.println (a + " <= " +b + " : "+ lowerequal);
    System.out.println (a + " > " +b + " : "+ greater);
    System.out.println (a + " >= " +b + " : "+ greaterequal);
    System.out.println (a + " == " +b + " : "+ equal);
    System.out.println (a + " != " +b + " : "+ notequal);
  }
}