fork download
  1. object Main extends App{
  2.  
  3. val PI = 3.14159
  4.  
  5. def round(numbah: Double) = Math.round(numbah * 100.0) / 100.0
  6.  
  7. def convert(input: String) = {
  8. val conversionType = input.takeRight(2)
  9. conversionType match {
  10. case "rd" => round(input.dropRight(2).toDouble * 180 / PI).toString + "r"
  11. case "dr" => round(input.dropRight(2).toDouble * PI / 180).toString + "d"
  12. case _ => "no candidate for conversion"
  13. }
  14. }
  15. //main
  16. val input1 = "3.1416rd"
  17. val input2 = "90dr"
  18. val input3 = "100cr"
  19. println(convert(input1))
  20. println(convert(input2))
  21. println(convert(input3))
  22. }
Success #stdin #stdout 0.35s 322496KB
stdin
Standard input is empty
stdout
180.0r
1.57d
no candidate for conversion