static void countSubarraysof1and0 ( int a [ ] , int n ) {
  int count1 = 0 , count0 = 0 ;
  int number1 = 0 , number0 = 0 ;
  for ( int i = 0 ;
  i < n ;
  i ++ ) {
    if ( a [ i ] == 1 ) {
      count1 += 1 ;
    }
    else {
      number1 += ( count1 ) * ( count1 + 1 ) / 2 ;
      count1 = 0 ;
    }
  }
  for ( int i = 0 ;
  i < n ;
  i ++ ) {
    if ( a [ i ] == 0 ) {
      count0 += 1 ;
    }
    else {
      number0 += ( count0 ) * ( count0 + 1 ) / 2 ;
      count0 = 0 ;
    }
  }
  if ( count1 > 0 ) number1 += ( count1 ) * ( count1 + 1 ) / 2 ;
  if ( count0 > 0 ) number0 += ( count0 ) * ( count0 + 1 ) / 2 ;
  System . out . println ( "Count of subarrays of 0 only: " + number0 ) ;
  System . out . println ( "\nCount of subarrays of 1 only: " + number1 ) ;
}

static void countSubarraysof1and0 ( int a [ ] , int n ) { int count1 = 0 , count0 = 0 ; int number1 = 0 , number0 = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( a [ i ] == 1 ) { count1 += 1 ; } else { number1 += ( count1 ) * ( count1 + 1 ) / 2 ; count1 = 0 ; } } for ( int i = 0 ; i < n ; i ++ ) { if ( a [ i ] == 0 ) { count0 += 1 ; } else { number0 += ( count0 ) * ( count0 + 1 ) / 2 ; count0 = 0 ; } } if ( count1 > 0 ) number1 += ( count1 ) * ( count1 + 1 ) / 2 ; if ( count0 > 0 ) number0 += ( count0 ) * ( count0 + 1 ) / 2 ; System . out . println ( " Count ▁ of ▁ subarrays ▁ of ▁ 0 ▁ only : ▁ " + number0 ) ; System . out . println ( " \n Count ▁ of ▁ subarrays ▁ of ▁ 1 ▁ only : ▁ " + number1 ) ; }
(method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (integral_type) name: (identifier) dimensions: (dimensions)) (formal_parameter type: (integral_type) name: (identifier))) body: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal)) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal)) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) condition: (binary_expression left: (identifier) right: (identifier)) update: (update_expression (identifier)) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (decimal_integer_literal))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (decimal_integer_literal)))) alternative: (block (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (binary_expression left: (parenthesized_expression (identifier)) right: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal)))) right: (decimal_integer_literal)))) (expression_statement (assignment_expression left: (identifier) right: (decimal_integer_literal))))))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) condition: (binary_expression left: (identifier) right: (identifier)) update: (update_expression (identifier)) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (decimal_integer_literal))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (decimal_integer_literal)))) alternative: (block (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (binary_expression left: (parenthesized_expression (identifier)) right: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal)))) right: (decimal_integer_literal)))) (expression_statement (assignment_expression left: (identifier) right: (decimal_integer_literal))))))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) consequence: (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (binary_expression left: (parenthesized_expression (identifier)) right: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal)))) right: (decimal_integer_literal))))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) consequence: (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (binary_expression left: (parenthesized_expression (identifier)) right: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal)))) right: (decimal_integer_literal))))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (binary_expression left: (string_literal) right: (identifier))))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (binary_expression left: (string_literal) right: (identifier)))))))