How to Groovy: Comments, Math Operators and Order of Operations

How to:

  • Comment
  • Math Operators (Integer and Floating)
  • Order of Operations

class GroovyTut {
static void main(String[] args) {

  println("Hello World"); 

   //comments can be added using "//" or "/* */" 

    
   // Integer math operators
    println("10 + 9 = " + (10 + 9));
    println("10 - 9 = " + (10 - 9));
    println("10 * 9 = " + (10 * 9));
    println("10 / 9 = " + (10.intdiv(9)));
    println("10 % 9 = " + (10 % 9));

    // Floating point math operators
    println("10.2 + 9.9 = " + (10.2.plus(9.9)));
    println("10.2 - 9.9 = " + (10.2.minus(9.9)));
    println("10.2 * 9.9 = " + (10.2.multiply(9.9)));
    println("10.2 / 9.9 = " + (10.2 / 9.9));

    // Order of operations
    println("3 + 2 * 10 = " + (3 + 2 * 10));
    println("(3 + 2) * 10 = " + ((3 + 2) * 10));


    }
}