public static int fibMonaccianSearch ( int arr [ ] , int x , int n ) {
  int fibMMm2 = 0 ;
  int fibMMm1 = 1 ;
  int fibM = fibMMm2 + fibMMm1 ;
  while ( fibM < n ) {
    fibMMm2 = fibMMm1 ;
    fibMMm1 = fibM ;
    fibM = fibMMm2 + fibMMm1 ;
  }
  int offset = - 1 ;
  while ( fibM > 1 ) {
    int i = min ( offset + fibMMm2 , n - 1 ) ;
    if ( arr [ i ] < x ) {
      fibM = fibMMm1 ;
      fibMMm1 = fibMMm2 ;
      fibMMm2 = fibM - fibMMm1 ;
      offset = i ;
    }
    else if ( arr [ i ] > x ) {
      fibM = fibMMm2 ;
      fibMMm1 = fibMMm1 - fibMMm2 ;
      fibMMm2 = fibM - fibMMm1 ;
    }
    else return i ;
  }
  if ( fibMMm1 == 1 && arr [ offset + 1 ] == x ) return offset + 1 ;
  return - 1 ;
}

public static int fibMonaccianSearch ( int arr [ ] , int x , int n ) { int fibMMm2 = 0 ; int fibMMm1 = 1 ; int fibM = fibMMm2 + fibMMm1 ; while ( fibM < n ) { fibMMm2 = fibMMm1 ; fibMMm1 = fibM ; fibM = fibMMm2 + fibMMm1 ; } int offset = - 1 ; while ( fibM > 1 ) { int i = min ( offset + fibMMm2 , n - 1 ) ; if ( arr [ i ] < x ) { fibM = fibMMm1 ; fibMMm1 = fibMMm2 ; fibMMm2 = fibM - fibMMm1 ; offset = i ; } else if ( arr [ i ] > x ) { fibM = fibMMm2 ; fibMMm1 = fibMMm1 - fibMMm2 ; fibMMm2 = fibM - fibMMm1 ; } else return i ; } if ( fibMMm1 == 1 && arr [ offset + 1 ] == x ) return offset + 1 ; return - 1 ; }
(method_declaration (modifiers) type: (integral_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (integral_type) name: (identifier) dimensions: (dimensions)) (formal_parameter type: (integral_type) name: (identifier)) (formal_parameter type: (integral_type) name: (identifier))) body: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (identifier) right: (identifier)))) (while_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) body: (block (expression_statement (assignment_expression left: (identifier) right: (identifier))) (expression_statement (assignment_expression left: (identifier) right: (identifier))) (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (identifier) right: (identifier)))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (unary_expression operand: (decimal_integer_literal)))) (while_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) body: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation name: (identifier) arguments: (argument_list (binary_expression left: (identifier) right: (identifier)) (binary_expression left: (identifier) right: (decimal_integer_literal)))))) (if_statement condition: (parenthesized_expression (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (identifier))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (identifier))) (expression_statement (assignment_expression left: (identifier) right: (identifier))) (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (identifier) right: (identifier)))) (expression_statement (assignment_expression left: (identifier) right: (identifier)))) alternative: (if_statement condition: (parenthesized_expression (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (identifier))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (identifier))) (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (identifier) right: (identifier)))) (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (identifier) right: (identifier))))) alternative: (return_statement (identifier)))))) (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (identifier) right: (decimal_integer_literal)) right: (binary_expression left: (array_access array: (identifier) index: (binary_expression left: (identifier) right: (decimal_integer_literal))) right: (identifier)))) consequence: (return_statement (binary_expression left: (identifier) right: (decimal_integer_literal)))) (return_statement (unary_expression operand: (decimal_integer_literal)))))