Scala program that sums two integers

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
object cli {
val HELP_MSG = "Usage: arg1 - number 1, arg2 - number 2"
def main(args: Array[String]): Unit = {
if (args.length != 2) {
System.err.println(HELP_MSG)
return
}
var num1: Int = 0
var num2: Int = 0
try {
num1 = args(0) toInt
} catch {
case ex: NumberFormatException =>
System.err.println(ex)
return
}
try {
num2 = args(1) toInt
} catch {
case ex: NumberFormatException =>
System.err.println(ex)
return
}
printf("%d\n", num1 + num2)
}
}