1,
import java.util.Scanner
/**
* Author: bruce
* Date: 2015-01-24
*/
object ConsoleScanner {
def main(args: Array[String]) {
println("Please enter a phase: ");
val scan = new Scanner(System.in);
val phase = scan.next()
algo(phase, "+")
algo(phase, "-")
algo(phase, "*")
algo(phase, "/")
}
def algo(phase: String, fu: String): Unit = {
val arr = phase.split("[" + fu + "]")
if (arr.length == 2) {
try {
arr(0).toInt
arr(1).toInt
println("result: " + (arr(0).toInt + arr(1).toInt))
} catch {
case e: NumberFormatException => println("type is not match")
}
}
}
}