Find a way to fill matrix with 1 ' s ▁ and ▁ 0' s in blank positions | Java implementation of the approach ; Function to generate and print the required matrix ; Replace the ' . ' ; Toggle number ; For each row , change the starting number ; Driver code
import java . io . * ; class GFG { static int N = 2 ; static int M = 2 ; static void Matrix ( char a [ ] [ ] ) { char ch = '1' ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < M ; j ++ ) { if ( a [ i ] [ j ] == ' . ' ) a [ i ] [ j ] = ch ; ch = ( ch == '1' ) ? '0' : '1' ; System . out . print ( a [ i ] [ j ] + " ▁ " ) ; } System . out . println ( ) ; if ( i % 2 == 0 ) ch = '0' ; else ch = '1' ; } } public static void main ( String [ ] args ) { char a [ ] [ ] = { { ' . ' , ' _ ' } , { ' _ ' , ' . ' } } ; Matrix ( a ) ; } }