Check if sum of count of digits of array elements is Prime or not | Java program for the above approach ; Function to check whether a number is prime or not ; Corner cases ; If given number is a multiple of 2 or 3 ; Function to check if sum of count of digits of all array elements is prime or not ; Initialize sum with 0 ; Traverse over the array ; Convert array element to string ; Add the count of digits to sum ; Print the result ; Drive Code ; Function call
import java . io . * ; import java . util . * ; class GFG { static boolean isPrime ( int n ) { if ( n <= 1 ) return false ; if ( n <= 3 ) return true ; if ( n % 2 == 0 n % 3 == 0 ) return false ; for ( int i = 5 ; i * i <= n ; i = i + 6 ) if ( n % i == 0 || n % ( i + 2 ) == 0 ) return false ; return true ; } static void CheckSumPrime ( int [ ] A , int N ) { int sum = 0 ; for ( int i = 0 ; i < N ; i ++ ) { String s = Integer . toString ( A [ i ] ) ; sum += s . length ( ) ; } if ( isPrime ( sum ) == true ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } public static void main ( String [ ] args ) { int [ ] A = { 1 , 11 , 12 } ; int N = A . length ; CheckSumPrime ( A , N ) ; } }