text: Count subarrays made up of single | Java program for the above approach ; Function to count of subarrays made up of single digit integers only ; Stores count of subarrays ; Stores the count of consecutive single digit numbers in the array ; Traverse the array ; Increment size of block by 1 ; Increment res by count ; Assign count = 0 ; Driver Code ; Given array ; Size of the array
code: class GFG { static void singleDigitSubarrayCount ( int arr [ ] , int N ) { int res = 0 ; int count = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( arr [ i ] <= 9 ) { count ++ ; res += count ; } else { count = 0 ; } } System . out . print ( res ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 0 , 1 , 14 , 2 , 5 } ; int N = arr . length ; singleDigitSubarrayCount ( arr , N ) ; } }