static String solveEquation ( String equation ) {
  int n = equation . length ( ) , sign = 1 , coeff = 0 ;
  int total = 0 , i = 0 ;
  for ( int j = 0 ;
  j < n ;
  j ++ ) {
    if ( equation . charAt ( j ) == '+' || equation . charAt ( j ) == '-' ) {
      if ( j > i ) total += sign * Integer . parseInt ( equation . substring ( i , j ) ) ;
      i = j ;
    }
    else if ( equation . charAt ( j ) == 'x' ) {
      if ( ( i == j ) || equation . charAt ( j - 1 ) == '+' ) coeff += sign ;
      else if ( equation . charAt ( j - 1 ) == '-' ) coeff -= sign ;
      else coeff += sign * Integer . parseInt ( equation . substring ( i , j ) ) ;
      i = j + 1 ;
    }
    else if ( equation . charAt ( j ) == '=' ) {
      if ( j > i ) total += sign * Integer . parseInt ( equation . substring ( i , j ) ) ;
      sign = - 1 ;
      i = j + 1 ;
    }
  }
  if ( i < n ) total = total + sign * Integer . parseInt ( equation . substring ( i ) ) ;
  if ( coeff == 0 && total == 0 ) return "Infinite solutions" ;
  if ( coeff == 0 && total != 0 ) return "No solution" ;
  int ans = - total / coeff ;
  return ( Integer . toString ( ans ) ) ;
}

static String solveEquation ( String equation ) { int n = equation . length ( ) , sign = 1 , coeff = 0 ; int total = 0 , i = 0 ; for ( int j = 0 ; j < n ; j ++ ) { if ( equation . charAt ( j ) == ' + ' || equation . charAt ( j ) == ' - ' ) { if ( j > i ) total += sign * Integer . parseInt ( equation . substring ( i , j ) ) ; i = j ; } else if ( equation . charAt ( j ) == ' x ' ) { if ( ( i == j ) || equation . charAt ( j - 1 ) == ' + ' ) coeff += sign ; else if ( equation . charAt ( j - 1 ) == ' - ' ) coeff -= sign ; else coeff += sign * Integer . parseInt ( equation . substring ( i , j ) ) ; i = j + 1 ; } else if ( equation . charAt ( j ) == ' = ' ) { if ( j > i ) total += sign * Integer . parseInt ( equation . substring ( i , j ) ) ; sign = - 1 ; i = j + 1 ; } } if ( i < n ) total = total + sign * Integer . parseInt ( equation . substring ( i ) ) ; if ( coeff == 0 && total == 0 ) return " Infinite ▁ solutions " ; if ( coeff == 0 && total != 0 ) return " No ▁ solution " ; int ans = - total / coeff ; return ( Integer . toString ( ans ) ) ; }
(method_declaration (modifiers) type: (type_identifier) name: (identifier) parameters: (formal_parameters (formal_parameter type: (type_identifier) name: (identifier))) body: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))) 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: (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))) right: (character_literal)) right: (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))) right: (character_literal)))) consequence: (block (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) consequence: (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (identifier))))))))) (expression_statement (assignment_expression left: (identifier) right: (identifier)))) alternative: (if_statement condition: (parenthesized_expression (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))) right: (character_literal))) consequence: (block (if_statement condition: (parenthesized_expression (binary_expression left: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) right: (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (binary_expression left: (identifier) right: (decimal_integer_literal)))) right: (character_literal)))) consequence: (expression_statement (assignment_expression left: (identifier) right: (identifier))) alternative: (if_statement condition: (parenthesized_expression (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (binary_expression left: (identifier) right: (decimal_integer_literal)))) right: (character_literal))) consequence: (expression_statement (assignment_expression left: (identifier) right: (identifier))) alternative: (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (identifier)))))))))) (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (identifier) right: (decimal_integer_literal))))) alternative: (if_statement condition: (parenthesized_expression (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))) right: (character_literal))) consequence: (block (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) consequence: (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (identifier))))))))) (expression_statement (assignment_expression left: (identifier) right: (unary_expression operand: (decimal_integer_literal)))) (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (identifier) right: (decimal_integer_literal)))))))))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) consequence: (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (identifier) right: (binary_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))))))))) (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (identifier) right: (decimal_integer_literal)) right: (binary_expression left: (identifier) right: (decimal_integer_literal)))) consequence: (return_statement (string_literal))) (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (identifier) right: (decimal_integer_literal)) right: (binary_expression left: (identifier) right: (decimal_integer_literal)))) consequence: (return_statement (string_literal))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (unary_expression operand: (identifier)) right: (identifier)))) (return_statement (parenthesized_expression (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))))))