Finish the program that counts all the prime numbers in a range of integers until . If , there will be no prime numbers.
Modifying collections
Counting primes
Report a typo
Sample Input 1:
1Sample Output 1:
0Write a program in Scala 3
object PrimeCounter extends App {
var list = ???
def count(i: Int, n: Int): Unit =
if (i <= n) {
val zeroModWithPrime = list.filter(prime => i % prime == ???)
if (zeroModWithPrime.isEmpty) list = i :: list
count(i + 1, ???)
}
val n = scala.io.StdIn.readInt()
if (n < 2)
???
else {
count(2, n)
println(???)
}
}
___
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.
Create a free account to access the full topic
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.