Count digits present in each element of a given Matrix | Java program for the above approach ; Function to count the number of digits in each element of the given matrix ; Traverse each row of arr [ ] [ ] ; Traverse each column of arr [ ] [ ] ; Store the current matrix element ; Count the number of digits ; Print the result ; Driver Code ; Given matrix
import java . util . * ; class GFG { static int M = 3 ; static int N = 3 ; static void countDigit ( int arr [ ] [ ] ) { for ( int i = 0 ; i < M ; i ++ ) { for ( int j = 0 ; j < N ; j ++ ) { int X = arr [ i ] [ j ] ; int d = ( int ) ( Math . floor ( Math . log10 ( X ) * 1.0 ) + 1 ) ; System . out . print ( d + " ▁ " ) ; } System . out . println ( ) ; } } public static void main ( String [ ] args ) { int arr [ ] [ ] = { { 27 , 173 , 5 } , { 21 , 6 , 624 } , { 5 , 321 , 49 } } ; countDigit ( arr ) ; } }