Find prime numbers in the first half and second half of an array | Java program to print the prime numbers in the first half and second half of an array ; Function to check if a number is prime or not ; Function to find whether elements are prime or not ; Traverse in the given range ; Check if a number is prime or not ; Function to print the prime numbers in the first half and second half of an array ; Driver Code ; Function call
import java . util . * ; class GFG { static boolean prime ( int n ) { for ( int i = 2 ; i * i <= n ; i ++ ) if ( n % i == 0 ) return false ; return true ; } static void prime_range ( int start , int end , int [ ] a ) { for ( int i = start ; i < end ; i ++ ) { if ( prime ( a [ i ] ) ) System . out . print ( a [ i ] + " ▁ " ) ; } } static void Print ( int arr [ ] , int n ) { System . out . print ( " Prime ▁ numbers ▁ in ▁ the ▁ first ▁ half ▁ are ▁ " ) ; prime_range ( 0 , n / 2 , arr ) ; System . out . println ( ) ; System . out . print ( " Prime ▁ numbers ▁ in ▁ the ▁ second ▁ half ▁ are ▁ " ) ; prime_range ( n / 2 , n , arr ) ; System . out . println ( ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 5 , 10 , 15 , 17 , 21 , 23 } ; int n = arr . length ; Print ( arr , n ) ; } }