find if the number is prime



    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)
        loop(x-1, n % x != 0 && stillprime)
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Playground
    • Snippets
    • Cookbooks
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.