Recursive program for prime number | java Program to find whether a Number is Prime or Not using Recursion ; Returns true if n is prime , else return false . i is current divisor to check . ; Base cases ; Check for next divisor ; Driver program to test above function
import java . util . * ; class GFG { static boolean isPrime ( int n , int i ) { if ( n <= 2 ) return ( n == 2 ) ? true : false ; if ( n % i == 0 ) return false ; if ( i * i > n ) return true ; return isPrime ( n , i + 1 ) ; } public static void main ( String [ ] args ) { int n = 15 ; if ( isPrime ( n , 2 ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }