Scala 範例程式 - 質數 (primes)

原始程式:primes.scala

/** Print prime numbers less than 100, very inefficiently */
object primes extends Application {
  def isPrime(n: Int) = (2 until n) forall (n % _ != 0)
  for (i <- 900 to 1000 if isPrime(i)) println(i)
}

執行結果:

D:\Scala\code>scalac primes.scala

D:\Scala\code>scala primes
907
911
919
929
937
941
947
953
967
971
977
983
991
997
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License