2015年8月15日土曜日

開発環境

Learning Scala: Practical Functional Programming for the JVM (Jason Swartz (著)、O'Reilly Media)のPart Ⅰ. (Core Scala)、Chapter 4.(Functions)、Exercises 4.(No. 1471)を解いてみる。

その他参考書籍

Exercises 4.(No. 1471)

コード(Emacs)

import java.util.Date
// 実行時に警告出るし、Java の Date class の使い方違うのかも    
def dhms(milliseconds: Int) : String = {
  val date = new Date(milliseconds)
  val days = date.getDate()
  val hours = date.getHours()
  val minutes = date.getMinutes()
  val seconds = date.getSeconds()
  s"$days days, $hours hours, $minutes minutes, $seconds seconds"
}

println(dhms(1000000000))

入出力結果(Terminal, REPL(Read, Eval, Print, Loop))

$ scala-2.11 sample4.scala
warning: there were four deprecation warnings; re-run with -deprecation for details
one warning found
12 days, 22 hours, 46 minutes, 40 seconds
$

0 コメント:

コメントを投稿