public static void floorAndCeil ( int arr [ ] , int x ) {
  int n = arr . length ;
  int fInd = - 1 , cInd = - 1 ;
  int fDist = Integer . MAX_VALUE , cDist = Integer . MAX_VALUE ;
  for ( int i = 0 ;
  i < n ;
  i ++ ) {
    if ( arr [ i ] >= x && cDist > ( arr [ i ] - x ) ) {
      cInd = i ;
      cDist = arr [ i ] - x ;
    }
    if ( arr [ i ] <= x && fDist > ( x - arr [ i ] ) ) {
      fInd = i ;
      fDist = x - arr [ i ] ;
    }
  }
  if ( fDist == Integer . MAX_VALUE ) System . out . println ( "Floor doesn't exist " ) ;
  else System . out . println ( "Floor is " + arr [ fInd ] ) ;
  if ( cDist == Integer . MAX_VALUE ) System . out . println ( "Ceil doesn't exist " ) ;
  else System . out . println ( "Ceil is  " + arr [ cInd ] ) ;
}

public static void floorAndCeil ( int arr [ ] , int x ) { int n = arr . length ; int fInd = - 1 , cInd = - 1 ; int fDist = Integer . MAX_VALUE , cDist = Integer . MAX_VALUE ; for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] >= x && cDist > ( arr [ i ] - x ) ) { cInd = i ; cDist = arr [ i ] - x ; } if ( arr [ i ] <= x && fDist > ( x - arr [ i ] ) ) { fInd = i ; fDist = x - arr [ i ] ; } } if ( fDist == Integer . MAX_VALUE ) System . out . println ( " Floor ▁ doesn ' t ▁ exist ▁ " ) ; else System . out . println ( " Floor ▁ is ▁ " + arr [ fInd ] ) ; if ( cDist == Integer . MAX_VALUE ) System . out . println ( " Ceil ▁ doesn ' t ▁ exist ▁ " ) ; else System . out . println ( " Ceil ▁ is ▁ ▁ " + arr [ cInd ] ) ; }
(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: (field_access object: (identifier) field: (identifier)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (unary_expression operand: (decimal_integer_literal))) declarator: (variable_declarator name: (identifier) value: (unary_expression operand: (decimal_integer_literal)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (field_access object: (identifier) field: (identifier))) declarator: (variable_declarator name: (identifier) value: (field_access object: (identifier) field: (identifier)))) (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: (array_access array: (identifier) index: (identifier)) right: (identifier)) right: (binary_expression left: (identifier) right: (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: (array_access array: (identifier) index: (identifier)) right: (identifier)))))) (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (identifier)) right: (binary_expression left: (identifier) right: (parenthesized_expression (binary_expression left: (identifier) right: (array_access array: (identifier) index: (identifier))))))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (identifier))) (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (identifier) right: (array_access array: (identifier) index: (identifier))))))))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (field_access object: (identifier) field: (identifier)))) consequence: (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (string_literal)))) alternative: (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (binary_expression left: (string_literal) right: (array_access array: (identifier) index: (identifier))))))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (field_access object: (identifier) field: (identifier)))) consequence: (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (string_literal)))) alternative: (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (binary_expression left: (string_literal) right: (array_access array: (identifier) index: (identifier)))))))))