Groovy Quiz 5 | Arithmetic Operators


Reference video | Groovy Playground


1 Point for every correct answer | Let’s Get Started

1.

Arithmetic operators – Check if the symbols and description matches

+ addition

- subtraction

* multiplication

/ division

% remainder

** power

 
 

2.

Guess the output of these Arithmetic Operations
(Can run and check code here – https://groovy-playground.appspot.com/)

//Arithmetic Operators
assert 1 + 2 == 3 
assert 4 - 3 == 1 
assert 3 * 5 == 15 
assert 3 / 2 == 1.5 
assert 10 % 3 == 1 
assert 2 ** 3 == 8
 
 

3.

Guess the output

print (9.intdiv(5) == 1)

 
 
 

4.

Guess the output

print (2.2.plus(3.3))

 
 
 

5.

Guess the output

//Unary Operators
println (+3 == 3)
println (-4 == 0 - 4)
println (-(-1) == 1)
 
 

6.

Guess the output

int i = 10
println i++
println i
 
 
 

7.

Guess the output

int i = 10
println ++i
println i
 
 

8.

Guess the output

//Unary operators
def a = 2 
def b = a++ * 3 
assert a == 3 && b == 6
 
 

9.

Guess the output

//Assignment arithmetic operators
def a = 4
a += 3
print a == 7
 
 
 

15