Advertisement
sidhartha11

scala function to test for prime number

Feb 24th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.28 KB | None | 0 0
  1. /** simple scala function to test is a number is a prime number **/  
  2.  
  3. def isPrime(p: Int): Boolean = {
  4.     val p1=math.abs(p)
  5.     if (p1 <= 3) return true
  6.     var t: Int = math.sqrt(p1).asInstanceOf[Int]
  7.     for ( i <- 2 to t if p1 % i == 0) return false
  8.     return true
  9.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement