Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Complex(val real: Int ,val imaginary: Int) {
- def +(operand: Complex) : Complex = {
- new Complex( real + operand.real , imaginary + operand.imaginary)
- }
- def -(operand: Complex) : Complex = {
- new Complex( real - operand.real , imaginary - operand.imaginary)
- }
- def *(operand: Complex) : Complex = {
- new Complex(real * operand.real - imaginary * operand.imaginary, real * operand.imaginary + imaginary * operand.real)
- }
- override def toString(): String = {
- real + (if (imaginary < 0) "" else "+") + imaginary + "i"
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement