Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Complex {
- Double re
- Double im
- String toString() {
- re + ' + ' + im + 'i'
- }
- Complex plus(Complex c) {
- new Complex(re: this.re + c.re, im: this.im + c.im)
- }
- }
- def c1 = new Complex(re:2, im:3.5)
- def c2 = new Complex(re:4.2, im:7.1)
- println 'c1 : ' + c1
- //c1 : 2.0 + 3.5i
- println 'c2 : ' + c2
- //c2 : 4.2 + 7.1i
- def result = c1 + c2
- println 'result : ' + result
- //result : 6.2 + 10.6i
-
Advertisement
Add Comment
Please, Sign In to add comment