Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

Compile and Execute Scala Online

class Hello {

    def main(args: Array[String]) { 
        //var primeList = findPrimes(1, 10);
        println("End of Program");
    } 
    
    //start from the lowest value n and work up
    def findPrimes(n: Int, m: Int): Stream[Int] = {
        //gets all the values who's square are less than m, 
        //then for each, checks to see if those values % != 0
        lazy val primes: Stream[Int] = Stream.from(n, m).filter(i => primes.takeWhile(k => k*k <= i).forall(j => i % j != 0))
        primes.foreach(i => println(i))
        return primes
     }//end of findPrimes
}

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.