Scally started a project to test if the input natural number is a prime number. Help her finish the function using the pattern matching technique.
Introduction to pattern matching
Primality Test
Report a typo
Sample Input 1:
1Sample Output 1:
falseWrite a program in Scala 3
def isPrime(input: Int, n: Int = 2): Boolean =
input match
case x if x < 2 => false
case x if n * n > x => ???
case x if ??? == 0 => false
case _ => isPrime(???, ???)
___
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.