Created
August 12, 2013 03:50
-
-
Save ozw-sei/6208131 to your computer and use it in GitHub Desktop.
Calc.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| object Calc{ | |
| def main(args: Array[String]) = { | |
| val two = Calc.add(1,1) | |
| val one = Calc.sub(2,1) | |
| val six = Calc.mul(3,2) | |
| val five = Calc.div(10,2) | |
| val err = try{ | |
| Calc.div(10,0) | |
| } | |
| catch{ | |
| case _:java.lang.IllegalArgumentException => { | |
| println("IllegalArgumentException") | |
| new IllegalArgumentException | |
| } | |
| } | |
| finally{ | |
| println("always called") | |
| } | |
| println("two = " + two) | |
| println("one = " + one) | |
| println("six = " + six) | |
| println("five = " + five) | |
| println("err = " + err) | |
| } | |
| def add(num1 : Int, num2 : Int) = num1 + num2 | |
| def sub(num1 : Int, num2 : Int) = num1 - num2 | |
| def mul(num1 : Int, num2 : Int) = num1 * num2 | |
| def div(num1 : Float, num2 : Float) = { | |
| import java.lang.IllegalArgumentException | |
| if(num2 == 0) | |
| throw new IllegalArgumentException("devide by zero") | |
| else | |
| num1 / num2 | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment