## Implement a simple calculator

degree of difficulty: 1

Implement a simple calculator which evaluates arithmetic expressions given as a String.
The expression should only consists of numbers 0 to 9, parenthesis, and the binary and unary operators + and -.
White spaces are ignored.
Implement a recursive descent parser for reading in the String.

The syntax is given as the following EBNF:

expression = term, [ "+" | "-" , term ] ;
term = "(", term, ")"
| "0" | "1" | ... | "9" ;

The follwing strings are valid: "1", "((2))", "2 + 3", "( (4) - 5 +7)".

Inspect the methods of a String and the class Character

Solution

## Euclids algorithm

degree of difficulty: 2

Implement Euclids algorithm recursivly. For flow control use the if-statement only.

Euclids algorithm to calculate the greates common divisor of two positive integer numbers a and b (gcd(a,b)) is recursivly defined as:

- gcd(a,b) := a if a = b
- gcd(a,b) := gcd(a - b, b) if a > b
- gcd(a,b) := gcd(a, b - a) if b > a

Solution