This code defines a function that checks whether a number is a prime. The function accepts an integer parameter and returns a boolean value indicating whether the number is prime or not. Note that the function uses a looping pattern to check whether the number is prime or not.
package example
object isprimeobj extends App{
println(s"hello world")
def isprime(n: Int): Boolean = {
def loop(x: Int, stillprime: Boolean): Boolean = {
if (x <= 1) return stillprime
else {
//println( n%x == 0)
//println("---")
loop(x-1, n % x != 0 && stillprime)
}
}
loop(n-1,true)
}
print(isprime(7))
}