code
stringlengths 31
2.27k
| tokenized_code
stringlengths 30
1.69k
| sexp
stringlengths 115
9.43k
|
---|---|---|
public static void main ( String [ ] args ) {
String str = "amazon" ;
String [ ] arr = {
"fds" , "oxq" , "zoa" , "epw" , "amn" };
Vector < String > v = new Vector < String > ( Arrays . asList ( arr ) ) ;
if ( isPossible ( v , str ) ) System . out . println ( "Yes" ) ;
else System . out . println ( "No" ) ;
}
| public static void main ( String [ ] args ) { String str = " amazon " ; String [ ] arr = { " fds " , " oxq " , " zoa " , " epw " , " amn " } ; Vector < String > v = new Vector < String > ( Arrays . asList ( arr ) ) ; if ( isPossible ( v , str ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } | (method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (array_type element: (type_identifier) dimensions: (dimensions)) name: (identifier))) body: (block (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (string_literal))) (local_variable_declaration type: (array_type element: (type_identifier) dimensions: (dimensions)) declarator: (variable_declarator name: (identifier) value: (array_initializer (string_literal) (string_literal) (string_literal) (string_literal) (string_literal)))) (local_variable_declaration type: (generic_type (type_identifier) (type_arguments (type_identifier))) declarator: (variable_declarator name: (identifier) value: (object_creation_expression type: (generic_type (type_identifier) (type_arguments (type_identifier))) arguments: (argument_list (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))))))) (if_statement condition: (parenthesized_expression (method_invocation name: (identifier) arguments: (argument_list (identifier) (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 (string_literal))))))) |
static void primesieve ( boolean [ ] prime ) {
prime [ 1 ] = false ;
for ( int p = 2 ;
p * p <= 650 ;
p ++ ) {
if ( prime [ p ] == true ) {
for ( int i = p * 2 ;
i <= 650 ;
i += p ) prime [ i ] = false ;
}
}
}
| static void primesieve ( boolean [ ] prime ) { prime [ 1 ] = false ; for ( int p = 2 ; p * p <= 650 ; p ++ ) { if ( prime [ p ] == true ) { for ( int i = p * 2 ; i <= 650 ; i += p ) prime [ i ] = false ; } } } | (method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (array_type element: (boolean_type) dimensions: (dimensions)) name: (identifier))) body: (block (expression_statement (assignment_expression left: (array_access array: (identifier) index: (decimal_integer_literal)) right: (false))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) condition: (binary_expression left: (binary_expression left: (identifier) right: (identifier)) right: (decimal_integer_literal)) update: (update_expression (identifier)) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (true))) consequence: (block (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (identifier) right: (decimal_integer_literal)))) condition: (binary_expression left: (identifier) right: (decimal_integer_literal)) update: (assignment_expression left: (identifier) right: (identifier)) body: (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (false)))))))))) |
static pair sum_sqsum ( int n ) {
int sum = 0 ;
int sqsum = 0 ;
int x ;
while ( n > 0 ) {
x = n % 10 ;
sum += x ;
sqsum += x * x ;
n /= 10 ;
}
return ( new pair ( sum , sqsum ) ) ;
}
| static pair sum_sqsum ( int n ) { int sum = 0 ; int sqsum = 0 ; int x ; while ( n > 0 ) { x = n % 10 ; sum += x ; sqsum += x * x ; n /= 10 ; } return ( new pair ( sum , sqsum ) ) ; } | (method_declaration (modifiers) type: (type_identifier) name: (identifier) parameters: (formal_parameters (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))) (while_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) body: (block (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (identifier) right: (decimal_integer_literal)))) (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: (decimal_integer_literal))))) (return_statement (parenthesized_expression (object_creation_expression type: (type_identifier) arguments: (argument_list (identifier) (identifier))))))) |
static int countnumber ( int L , int R ) {
boolean [ ] prime = new boolean [ 651 ] ;
Arrays . fill ( prime , true ) ;
primesieve ( prime ) ;
int cnt = 0 ;
for ( int i = L ;
i <= R ;
i ++ ) {
pair digit = sum_sqsum ( i ) ;
if ( prime [ digit . first ] && prime [ digit . second ] ) {
cnt += 1 ;
}
}
return cnt ;
}
| static int countnumber ( int L , int R ) { boolean [ ] prime = new boolean [ 651 ] ; Arrays . fill ( prime , true ) ; primesieve ( prime ) ; int cnt = 0 ; for ( int i = L ; i <= R ; i ++ ) { pair digit = sum_sqsum ( i ) ; if ( prime [ digit . first ] && prime [ digit . second ] ) { cnt += 1 ; } } return cnt ; } | (method_declaration (modifiers) type: (integral_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (integral_type) name: (identifier)) (formal_parameter type: (integral_type) name: (identifier))) body: (block (local_variable_declaration type: (array_type element: (boolean_type) dimensions: (dimensions)) declarator: (variable_declarator name: (identifier) value: (array_creation_expression type: (boolean_type) dimensions: (dimensions_expr (decimal_integer_literal))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (true)))) (expression_statement (method_invocation name: (identifier) arguments: (argument_list (identifier)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (identifier))) condition: (binary_expression left: (identifier) right: (identifier)) update: (update_expression (identifier)) body: (block (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (method_invocation name: (identifier) arguments: (argument_list (identifier))))) (if_statement condition: (parenthesized_expression (binary_expression left: (array_access array: (identifier) index: (field_access object: (identifier) field: (identifier))) right: (array_access array: (identifier) index: (field_access object: (identifier) field: (identifier))))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (decimal_integer_literal))))))) (return_statement (identifier)))) |
public static void main ( String [ ] args ) {
int L = 10 ;
int R = 20 ;
System . out . println ( countnumber ( L , R ) ) ;
}
| public static void main ( String [ ] args ) { int L = 10 ; int R = 20 ; System . out . println ( countnumber ( L , R ) ) ; } | (method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (array_type element: (type_identifier) dimensions: (dimensions)) 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))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (method_invocation name: (identifier) arguments: (argument_list (identifier) (identifier)))))))) |
static float sumOfAP ( float a , float d , int n ) {
float sum = 0 ;
for ( int i = 0 ;
i < n ;
i ++ ) {
sum = sum + a ;
a = a + d ;
}
return sum ;
}
| static float sumOfAP ( float a , float d , int n ) { float sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { sum = sum + a ; a = a + d ; } return sum ; } | (method_declaration (modifiers) type: (floating_point_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (floating_point_type) name: (identifier)) (formal_parameter type: (floating_point_type) name: (identifier)) (formal_parameter type: (integral_type) name: (identifier))) body: (block (local_variable_declaration type: (floating_point_type) 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 (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)))))) (return_statement (identifier)))) |
public static void main ( String args [ ] ) {
int n = 20 ;
float a = 2.5f , d = 1.5f ;
System . out . println ( sumOfAP ( a , d , n ) ) ;
}
| public static void main ( String args [ ] ) { int n = 20 ; float a = 2.5f , d = 1.5f ; System . out . println ( sumOfAP ( a , d , n ) ) ; } | (method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (type_identifier) name: (identifier) dimensions: (dimensions))) body: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (local_variable_declaration type: (floating_point_type) declarator: (variable_declarator name: (identifier) value: (decimal_floating_point_literal)) declarator: (variable_declarator name: (identifier) value: (decimal_floating_point_literal))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (method_invocation name: (identifier) arguments: (argument_list (identifier) (identifier) (identifier)))))))) |
static int factorial ( int n ) {
int fact = 1 , i ;
if ( n == 0 ) return 1 ;
for ( i = 1 ;
i <= n ;
i ++ ) fact *= i ;
return fact ;
}
| static int factorial ( int n ) { int fact = 1 , i ; if ( n == 0 ) return 1 ; for ( i = 1 ; i <= n ; i ++ ) fact *= i ; return fact ; } | (method_declaration (modifiers) type: (integral_type) name: (identifier) parameters: (formal_parameters (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))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) consequence: (return_statement (decimal_integer_literal))) (for_statement init: (assignment_expression left: (identifier) right: (decimal_integer_literal)) condition: (binary_expression left: (identifier) right: (identifier)) update: (update_expression (identifier)) body: (expression_statement (assignment_expression left: (identifier) right: (identifier)))) (return_statement (identifier)))) |
static void findmiddle ( int A , int X , int n ) {
int i , j , aPow , xPow ;
float middleTerm1 , middleTerm2 ;
if ( n % 2 == 0 ) {
i = n / 2 ;
aPow = ( int ) Math . pow ( A , n - i ) ;
xPow = ( int ) Math . pow ( X , i ) ;
middleTerm1 = ( ( float ) factorial ( n ) / ( factorial ( n - i ) * factorial ( i ) ) ) * aPow * xPow ;
System . out . println ( "MiddleTerm = " + middleTerm1 ) ;
}
else {
i = ( n - 1 ) / 2 ;
j = ( n + 1 ) / 2 ;
aPow = ( int ) Math . pow ( A , n - i ) ;
xPow = ( int ) Math . pow ( X , i ) ;
middleTerm1 = ( ( float ) factorial ( n ) / ( factorial ( n - i ) * factorial ( i ) ) ) * aPow * xPow ;
aPow = ( int ) Math . pow ( A , n - j ) ;
xPow = ( int ) Math . pow ( X , j ) ;
middleTerm2 = ( ( float ) factorial ( n ) / ( factorial ( n - j ) * factorial ( j ) ) ) * aPow * xPow ;
System . out . println ( "MiddleTerm1 = " + middleTerm1 ) ;
System . out . println ( "MiddleTerm2 = " + middleTerm2 ) ;
}
}
| static void findmiddle ( int A , int X , int n ) { int i , j , aPow , xPow ; float middleTerm1 , middleTerm2 ; if ( n % 2 == 0 ) { i = n / 2 ; aPow = ( int ) Math . pow ( A , n - i ) ; xPow = ( int ) Math . pow ( X , i ) ; middleTerm1 = ( ( float ) factorial ( n ) / ( factorial ( n - i ) * factorial ( i ) ) ) * aPow * xPow ; System . out . println ( " MiddleTerm β = β " + middleTerm1 ) ; } else { i = ( n - 1 ) / 2 ; j = ( n + 1 ) / 2 ; aPow = ( int ) Math . pow ( A , n - i ) ; xPow = ( int ) Math . pow ( X , i ) ; middleTerm1 = ( ( float ) factorial ( n ) / ( factorial ( n - i ) * factorial ( i ) ) ) * aPow * xPow ; aPow = ( int ) Math . pow ( A , n - j ) ; xPow = ( int ) Math . pow ( X , j ) ; middleTerm2 = ( ( float ) factorial ( n ) / ( factorial ( n - j ) * factorial ( j ) ) ) * aPow * xPow ; System . out . println ( " MiddleTerm1 β = β " + middleTerm1 ) ; System . out . println ( " MiddleTerm2 β = β " + middleTerm2 ) ; } } | (method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (integral_type) name: (identifier)) (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)) declarator: (variable_declarator name: (identifier)) declarator: (variable_declarator name: (identifier)) declarator: (variable_declarator name: (identifier))) (local_variable_declaration type: (floating_point_type) declarator: (variable_declarator name: (identifier)) declarator: (variable_declarator name: (identifier))) (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (identifier) right: (decimal_integer_literal)) right: (decimal_integer_literal))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (identifier) right: (decimal_integer_literal)))) (expression_statement (assignment_expression left: (identifier) right: (cast_expression type: (integral_type) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (binary_expression left: (identifier) right: (identifier))))))) (expression_statement (assignment_expression left: (identifier) right: (cast_expression type: (integral_type) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (identifier)))))) (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (binary_expression left: (parenthesized_expression (binary_expression left: (cast_expression type: (floating_point_type) value: (method_invocation name: (identifier) arguments: (argument_list (identifier)))) right: (parenthesized_expression (binary_expression left: (method_invocation name: (identifier) arguments: (argument_list (binary_expression left: (identifier) right: (identifier)))) right: (method_invocation name: (identifier) arguments: (argument_list (identifier))))))) right: (identifier)) 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)))))) alternative: (block (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) right: (decimal_integer_literal)))) (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) right: (decimal_integer_literal)))) (expression_statement (assignment_expression left: (identifier) right: (cast_expression type: (integral_type) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (binary_expression left: (identifier) right: (identifier))))))) (expression_statement (assignment_expression left: (identifier) right: (cast_expression type: (integral_type) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (identifier)))))) (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (binary_expression left: (parenthesized_expression (binary_expression left: (cast_expression type: (floating_point_type) value: (method_invocation name: (identifier) arguments: (argument_list (identifier)))) right: (parenthesized_expression (binary_expression left: (method_invocation name: (identifier) arguments: (argument_list (binary_expression left: (identifier) right: (identifier)))) right: (method_invocation name: (identifier) arguments: (argument_list (identifier))))))) right: (identifier)) right: (identifier)))) (expression_statement (assignment_expression left: (identifier) right: (cast_expression type: (integral_type) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (binary_expression left: (identifier) right: (identifier))))))) (expression_statement (assignment_expression left: (identifier) right: (cast_expression type: (integral_type) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (identifier)))))) (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (binary_expression left: (parenthesized_expression (binary_expression left: (cast_expression type: (floating_point_type) value: (method_invocation name: (identifier) arguments: (argument_list (identifier)))) right: (parenthesized_expression (binary_expression left: (method_invocation name: (identifier) arguments: (argument_list (binary_expression left: (identifier) right: (identifier)))) right: (method_invocation name: (identifier) arguments: (argument_list (identifier))))))) right: (identifier)) 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))))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (binary_expression left: (string_literal) right: (identifier))))))))) |
public static void main ( String [ ] args ) {
int n = 6 , A = 2 , X = 4 ;
findmiddle ( A , X , n ) ;
}
| public static void main ( String [ ] args ) { int n = 6 , A = 2 , X = 4 ; findmiddle ( A , X , n ) ; } | (method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (array_type element: (type_identifier) dimensions: (dimensions)) 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)) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (expression_statement (method_invocation name: (identifier) arguments: (argument_list (identifier) (identifier) (identifier)))))) |
static int maxOR ( int arr [ ] , int n ) {
int maxVal = 0 ;
for ( int i = 0 ;
i < n - 1 ;
i ++ ) for ( int j = i + 1 ;
j < n ;
j ++ ) {
maxVal = Math . max ( maxVal , arr [ i ] | arr [ j ] ) ;
}
return maxVal ;
}
| static int maxOR ( int arr [ ] , int n ) { int maxVal = 0 ; for ( int i = 0 ; i < n - 1 ; i ++ ) for ( int j = i + 1 ; j < n ; j ++ ) { maxVal = Math . max ( maxVal , arr [ i ] | arr [ j ] ) ; } return maxVal ; } | (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))) body: (block (local_variable_declaration type: (integral_type) 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: (binary_expression left: (identifier) right: (decimal_integer_literal))) update: (update_expression (identifier)) body: (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (identifier) right: (decimal_integer_literal)))) condition: (binary_expression left: (identifier) right: (identifier)) update: (update_expression (identifier)) body: (block (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (array_access array: (identifier) index: (identifier)))))))))) (return_statement (identifier)))) |
public static void main ( String [ ] args ) {
int arr [ ] = {
4 , 8 , 12 , 16 };
int n = arr . length ;
System . out . println ( maxOR ( arr , n ) ) ;
}
| public static void main ( String [ ] args ) { int arr [ ] = { 4 , 8 , 12 , 16 } ; int n = arr . length ; System . out . println ( maxOR ( arr , n ) ) ; } | (method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (array_type element: (type_identifier) dimensions: (dimensions)) name: (identifier))) body: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) dimensions: (dimensions) value: (array_initializer (decimal_integer_literal) (decimal_integer_literal) (decimal_integer_literal) (decimal_integer_literal)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (field_access object: (identifier) field: (identifier)))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (method_invocation name: (identifier) arguments: (argument_list (identifier) (identifier)))))))) |
static int xor_triplet ( int arr [ ] , int n ) {
int ans = 0 ;
for ( int i = 0 ;
i < n ;
i ++ ) {
for ( int j = i + 1 ;
j < n ;
j ++ ) {
for ( int k = j ;
k < n ;
k ++ ) {
int xor1 = 0 , xor2 = 0 ;
for ( int x = i ;
x < j ;
x ++ ) {
xor1 ^= arr [ x ] ;
}
for ( int x = j ;
x <= k ;
x ++ ) {
xor2 ^= arr [ x ] ;
}
if ( xor1 == xor2 ) {
ans ++ ;
}
}
}
}
return ans ;
}
| static int xor_triplet ( int arr [ ] , int n ) { int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = i + 1 ; j < n ; j ++ ) { for ( int k = j ; k < n ; k ++ ) { int xor1 = 0 , xor2 = 0 ; for ( int x = i ; x < j ; x ++ ) { xor1 ^= arr [ x ] ; } for ( int x = j ; x <= k ; x ++ ) { xor2 ^= arr [ x ] ; } if ( xor1 == xor2 ) { ans ++ ; } } } } return ans ; } | (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))) body: (block (local_variable_declaration type: (integral_type) 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 (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (identifier) right: (decimal_integer_literal)))) condition: (binary_expression left: (identifier) right: (identifier)) update: (update_expression (identifier)) body: (block (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (identifier))) condition: (binary_expression left: (identifier) right: (identifier)) update: (update_expression (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))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (identifier))) condition: (binary_expression left: (identifier) right: (identifier)) update: (update_expression (identifier)) body: (block (expression_statement (assignment_expression left: (identifier) right: (array_access array: (identifier) index: (identifier)))))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (identifier))) condition: (binary_expression left: (identifier) right: (identifier)) update: (update_expression (identifier)) body: (block (expression_statement (assignment_expression left: (identifier) right: (array_access array: (identifier) index: (identifier)))))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) consequence: (block (expression_statement (update_expression (identifier))))))))))) (return_statement (identifier)))) |
public static void main ( String [ ] args ) {
int arr [ ] = {
1 , 2 , 3 , 4 , 5 };
int n = arr . length ;
System . out . println ( xor_triplet ( arr , n ) ) ;
}
| public static void main ( String [ ] args ) { int arr [ ] = { 1 , 2 , 3 , 4 , 5 } ; int n = arr . length ; System . out . println ( xor_triplet ( arr , n ) ) ; } | (method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (array_type element: (type_identifier) dimensions: (dimensions)) name: (identifier))) body: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) dimensions: (dimensions) value: (array_initializer (decimal_integer_literal) (decimal_integer_literal) (decimal_integer_literal) (decimal_integer_literal) (decimal_integer_literal)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (field_access object: (identifier) field: (identifier)))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (method_invocation name: (identifier) arguments: (argument_list (identifier) (identifier)))))))) |
static int getMax ( int inputArray [ ] ) {
int maxValue = inputArray [ 0 ] ;
for ( int i = 1 ;
i < inputArray . length ;
i ++ ) {
if ( inputArray [ i ] > maxValue ) {
maxValue = inputArray [ i ] ;
}
}
return maxValue ;
}
| static int getMax ( int inputArray [ ] ) { int maxValue = inputArray [ 0 ] ; for ( int i = 1 ; i < inputArray . length ; i ++ ) { if ( inputArray [ i ] > maxValue ) { maxValue = inputArray [ i ] ; } } return maxValue ; } | (method_declaration (modifiers) type: (integral_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (integral_type) name: (identifier) dimensions: (dimensions))) body: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (array_access array: (identifier) index: (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: (field_access object: (identifier) field: (identifier))) update: (update_expression (identifier)) body: (block (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: (array_access array: (identifier) index: (identifier)))))))) (return_statement (identifier)))) |
static int minSteps ( int arr [ ] , int n ) {
int maxVal = getMax ( arr ) ;
return maxVal ;
}
| static int minSteps ( int arr [ ] , int n ) { int maxVal = getMax ( arr ) ; return maxVal ; } | (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))) body: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation name: (identifier) arguments: (argument_list (identifier))))) (return_statement (identifier)))) |
public static void main ( String [ ] args ) {
int arr [ ] = {
1 , 2 , 4 };
int n = arr . length ;
System . out . println ( minSteps ( arr , n ) ) ;
}
| public static void main ( String [ ] args ) { int arr [ ] = { 1 , 2 , 4 } ; int n = arr . length ; System . out . println ( minSteps ( arr , n ) ) ; } | (method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (array_type element: (type_identifier) dimensions: (dimensions)) name: (identifier))) body: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) dimensions: (dimensions) value: (array_initializer (decimal_integer_literal) (decimal_integer_literal) (decimal_integer_literal)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (field_access object: (identifier) field: (identifier)))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (method_invocation name: (identifier) arguments: (argument_list (identifier) (identifier)))))))) |
static int NumberofTimes ( String str ) {
int temporary_sum = 0 , count = 0 ;
while ( str . length ( ) > 1 ) {
temporary_sum = 0 ;
for ( int i = 0 ;
i < str . length ( ) ;
i ++ ) temporary_sum += ( str . charAt ( i ) - '0' ) ;
str = temporary_sum + "" ;
count ++ ;
}
return count ;
}
| static int NumberofTimes ( String str ) { int temporary_sum = 0 , count = 0 ; while ( str . length ( ) > 1 ) { temporary_sum = 0 ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) temporary_sum += ( str . charAt ( i ) - '0' ) ; str = temporary_sum + " " ; count ++ ; } return count ; } | (method_declaration (modifiers) type: (integral_type) 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: (decimal_integer_literal)) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (while_statement condition: (parenthesized_expression (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)) right: (decimal_integer_literal))) body: (block (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: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))) update: (update_expression (identifier)) body: (expression_statement (assignment_expression left: (identifier) right: (parenthesized_expression (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))) right: (character_literal)))))) (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (identifier) right: (string_literal)))) (expression_statement (update_expression (identifier))))) (return_statement (identifier)))) |
public static void main ( String [ ] args ) {
String s = "991" ;
System . out . println ( NumberofTimes ( s ) ) ;
}
| public static void main ( String [ ] args ) { String s = "991" ; System . out . println ( NumberofTimes ( s ) ) ; } | (method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (array_type element: (type_identifier) dimensions: (dimensions)) name: (identifier))) body: (block (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (string_literal))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (method_invocation name: (identifier) arguments: (argument_list (identifier)))))))) |
static boolean checkPalindrome ( String str ) {
int len = str . length ( ) ;
len -- ;
for ( int i = 0 ;
i < len ;
i ++ ) {
if ( str . charAt ( i ) != str . charAt ( len ) ) return false ;
len -- ;
}
return true ;
}
| static boolean checkPalindrome ( String str ) { int len = str . length ( ) ; len -- ; for ( int i = 0 ; i < len ; i ++ ) { if ( str . charAt ( i ) != str . charAt ( len ) ) return false ; len -- ; } return true ; } | (method_declaration (modifiers) type: (boolean_type) 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)))) (expression_statement (update_expression (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: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))))) consequence: (return_statement (false))) (expression_statement (update_expression (identifier))))) (return_statement (true)))) |
static void printSolution ( ArrayList < ArrayList < String >> partitions ) {
for ( ArrayList < String > i : partitions ) {
for ( String j : i ) {
System . out . print ( j + " " ) ;
}
System . out . println ( ) ;
}
}
| static void printSolution ( ArrayList < ArrayList < String > > partitions ) { for ( ArrayList < String > i : partitions ) { for ( String j : i ) { System . out . print ( j + " β " ) ; } System . out . println ( ) ; } } | (method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (generic_type (type_identifier) (type_arguments (generic_type (type_identifier) (type_arguments (type_identifier))))) name: (identifier))) body: (block (enhanced_for_statement type: (generic_type (type_identifier) (type_arguments (type_identifier))) name: (identifier) value: (identifier) body: (block (enhanced_for_statement type: (type_identifier) name: (identifier) value: (identifier) body: (block (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (binary_expression left: (identifier) right: (string_literal))))))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list))))))) |
static ArrayList < ArrayList < String >> addStrings ( ArrayList < ArrayList < String >> v , String s , ArrayList < String > temp , int index ) {
int len = s . length ( ) ;
String str = "" ;
ArrayList < String > current = new ArrayList < > ( temp ) ;
if ( index == 0 ) temp . clear ( ) ;
for ( int i = index ;
i < len ;
++ i ) {
str = str + s . charAt ( i ) ;
if ( checkPalindrome ( str ) ) {
temp . add ( str ) ;
if ( i + 1 < len ) {
v = addStrings ( v , s , temp , i + 1 ) ;
}
else {
v . add ( temp ) ;
}
temp = new ArrayList < > ( current ) ;
}
}
return v ;
}
| static ArrayList < ArrayList < String > > addStrings ( ArrayList < ArrayList < String > > v , String s , ArrayList < String > temp , int index ) { int len = s . length ( ) ; String str = " " ; ArrayList < String > current = new ArrayList < > ( temp ) ; if ( index == 0 ) temp . clear ( ) ; for ( int i = index ; i < len ; ++ i ) { str = str + s . charAt ( i ) ; if ( checkPalindrome ( str ) ) { temp . add ( str ) ; if ( i + 1 < len ) { v = addStrings ( v , s , temp , i + 1 ) ; } else { v . add ( temp ) ; } temp = new ArrayList < > ( current ) ; } } return v ; } | (method_declaration (modifiers) type: (generic_type (type_identifier) (type_arguments (generic_type (type_identifier) (type_arguments (type_identifier))))) name: (identifier) parameters: (formal_parameters (formal_parameter type: (generic_type (type_identifier) (type_arguments (generic_type (type_identifier) (type_arguments (type_identifier))))) name: (identifier)) (formal_parameter type: (type_identifier) name: (identifier)) (formal_parameter type: (generic_type (type_identifier) (type_arguments (type_identifier))) name: (identifier)) (formal_parameter type: (integral_type) 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)))) (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (string_literal))) (local_variable_declaration type: (generic_type (type_identifier) (type_arguments (type_identifier))) declarator: (variable_declarator name: (identifier) value: (object_creation_expression type: (generic_type (type_identifier) (type_arguments)) arguments: (argument_list (identifier))))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) consequence: (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (identifier))) condition: (binary_expression left: (identifier) right: (identifier)) update: (update_expression (identifier)) body: (block (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))))) (if_statement condition: (parenthesized_expression (method_invocation name: (identifier) arguments: (argument_list (identifier)))) consequence: (block (expression_statement (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: (identifier))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (method_invocation name: (identifier) arguments: (argument_list (identifier) (identifier) (identifier) (binary_expression left: (identifier) right: (decimal_integer_literal))))))) alternative: (block (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))))) (expression_statement (assignment_expression left: (identifier) right: (object_creation_expression type: (generic_type (type_identifier) (type_arguments)) arguments: (argument_list (identifier))))))))) (return_statement (identifier)))) |
static void partition ( String s , ArrayList < ArrayList < String >> v ) {
ArrayList < String > temp = new ArrayList < > ( ) ;
v = addStrings ( v , s , temp , 0 ) ;
printSolution ( v ) ;
}
| static void partition ( String s , ArrayList < ArrayList < String > > v ) { ArrayList < String > temp = new ArrayList < > ( ) ; v = addStrings ( v , s , temp , 0 ) ; printSolution ( v ) ; } | (method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (type_identifier) name: (identifier)) (formal_parameter type: (generic_type (type_identifier) (type_arguments (generic_type (type_identifier) (type_arguments (type_identifier))))) name: (identifier))) body: (block (local_variable_declaration type: (generic_type (type_identifier) (type_arguments (type_identifier))) declarator: (variable_declarator name: (identifier) value: (object_creation_expression type: (generic_type (type_identifier) (type_arguments)) arguments: (argument_list)))) (expression_statement (assignment_expression left: (identifier) right: (method_invocation name: (identifier) arguments: (argument_list (identifier) (identifier) (identifier) (decimal_integer_literal))))) (expression_statement (method_invocation name: (identifier) arguments: (argument_list (identifier)))))) |
public static void main ( String args [ ] ) {
String s = "geeks" ;
ArrayList < ArrayList < String >> partitions = new ArrayList < > ( ) ;
partition ( s , partitions ) ;
}
| public static void main ( String args [ ] ) { String s = " geeks " ; ArrayList < ArrayList < String > > partitions = new ArrayList < > ( ) ; partition ( s , partitions ) ; } | (method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (type_identifier) name: (identifier) dimensions: (dimensions))) body: (block (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (string_literal))) (local_variable_declaration type: (generic_type (type_identifier) (type_arguments (generic_type (type_identifier) (type_arguments (type_identifier))))) declarator: (variable_declarator name: (identifier) value: (object_creation_expression type: (generic_type (type_identifier) (type_arguments)) arguments: (argument_list)))) (expression_statement (method_invocation name: (identifier) arguments: (argument_list (identifier) (identifier)))))) |
static int solve ( int arr [ ] , int n ) {
Arrays . sort ( arr ) ;
int a = 0 , b = 0 ;
for ( int i = 0 ;
i < n ;
i ++ ) {
if ( i % 2 != 0 ) a = a * 10 + arr [ i ] ;
else b = b * 10 + arr [ i ] ;
}
return a + b ;
}
| static int solve ( int arr [ ] , int n ) { Arrays . sort ( arr ) ; int a = 0 , b = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( i % 2 != 0 ) a = a * 10 + arr [ i ] ; else b = b * 10 + arr [ i ] ; } return a + b ; } | (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))) body: (block (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))) (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: (identifier) right: (decimal_integer_literal)) right: (decimal_integer_literal))) consequence: (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (binary_expression left: (identifier) right: (decimal_integer_literal)) right: (array_access array: (identifier) index: (identifier))))) alternative: (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (binary_expression left: (identifier) right: (decimal_integer_literal)) right: (array_access array: (identifier) index: (identifier)))))))) (return_statement (binary_expression left: (identifier) right: (identifier))))) |
public static void main ( String [ ] args ) {
int arr [ ] = {
6 , 8 , 4 , 5 , 2 , 3 };
int n = arr . length ;
System . out . print ( "Sum is " + solve ( arr , n ) ) ;
}
| public static void main ( String [ ] args ) { int arr [ ] = { 6 , 8 , 4 , 5 , 2 , 3 } ; int n = arr . length ; System . out . print ( " Sum β is β " + solve ( arr , n ) ) ; } | (method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (array_type element: (type_identifier) dimensions: (dimensions)) name: (identifier))) body: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) dimensions: (dimensions) value: (array_initializer (decimal_integer_literal) (decimal_integer_literal) (decimal_integer_literal) (decimal_integer_literal) (decimal_integer_literal) (decimal_integer_literal)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (field_access object: (identifier) field: (identifier)))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (binary_expression left: (string_literal) right: (method_invocation name: (identifier) arguments: (argument_list (identifier) (identifier))))))))) |
static int countX ( int a , int b ) {
if ( b > a ) return 0 ;
else if ( a == b ) return - 1 ;
else {
int x = a - b , ans = 0 ;
for ( int i = 1 ;
i * i <= x ;
i ++ ) {
if ( x % i == 0 ) {
int d1 = i , d2 = b - 1 ;
if ( i * i != x ) d2 = x / i ;
if ( d1 > b ) ans ++ ;
if ( d2 > b ) ans ++ ;
}
}
return ans ;
}
}
| static int countX ( int a , int b ) { if ( b > a ) return 0 ; else if ( a == b ) return - 1 ; else { int x = a - b , ans = 0 ; for ( int i = 1 ; i * i <= x ; i ++ ) { if ( x % i == 0 ) { int d1 = i , d2 = b - 1 ; if ( i * i != x ) d2 = x / i ; if ( d1 > b ) ans ++ ; if ( d2 > b ) ans ++ ; } } return ans ; } } | (method_declaration (modifiers) type: (integral_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (integral_type) name: (identifier)) (formal_parameter type: (integral_type) name: (identifier))) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) consequence: (return_statement (decimal_integer_literal)) alternative: (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) consequence: (return_statement (unary_expression operand: (decimal_integer_literal))) alternative: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (identifier) right: (identifier))) 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: (binary_expression left: (identifier) right: (identifier)) right: (identifier)) update: (update_expression (identifier)) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (identifier) right: (identifier)) right: (decimal_integer_literal))) consequence: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (identifier)) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (identifier) right: (decimal_integer_literal)))) (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (identifier) right: (identifier)) right: (identifier))) consequence: (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (identifier) right: (identifier))))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) consequence: (expression_statement (update_expression (identifier)))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) consequence: (expression_statement (update_expression (identifier)))))))) (return_statement (identifier))))))) |
static public void main ( String args [ ] ) {
int a = 21 , b = 5 ;
System . out . println ( countX ( a , b ) ) ;
}
| static public void main ( String args [ ] ) { int a = 21 , b = 5 ; System . out . println ( countX ( a , b ) ) ; } | (method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (type_identifier) name: (identifier) dimensions: (dimensions))) 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))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (method_invocation name: (identifier) arguments: (argument_list (identifier) (identifier)))))))) |
static int findLargestDivisor ( int n ) {
for ( int i = 2 ;
i < Math . sqrt ( n ) + 1 ;
i ++ ) {
while ( n % ( i * i ) == 0 ) {
n = n / i ;
}
}
return n ;
}
| static int findLargestDivisor ( int n ) { for ( int i = 2 ; i < Math . sqrt ( n ) + 1 ; i ++ ) { while ( n % ( i * i ) == 0 ) { n = n / i ; } } return n ; } | (method_declaration (modifiers) type: (integral_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (integral_type) name: (identifier))) body: (block (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) condition: (binary_expression left: (identifier) right: (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))) right: (decimal_integer_literal))) update: (update_expression (identifier)) body: (block (while_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (identifier) right: (parenthesized_expression (binary_expression left: (identifier) right: (identifier)))) right: (decimal_integer_literal))) body: (block (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (identifier) right: (identifier)))))))) (return_statement (identifier)))) |
public static void main ( String args [ ] ) {
int n = 12 ;
System . out . println ( findLargestDivisor ( n ) ) ;
n = 97 ;
System . out . println ( findLargestDivisor ( n ) ) ;
}
| public static void main ( String args [ ] ) { int n = 12 ; System . out . println ( findLargestDivisor ( n ) ) ; n = 97 ; System . out . println ( findLargestDivisor ( n ) ) ; } | (method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (type_identifier) name: (identifier) dimensions: (dimensions))) body: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (method_invocation name: (identifier) arguments: (argument_list (identifier)))))) (expression_statement (assignment_expression left: (identifier) right: (decimal_integer_literal))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (method_invocation name: (identifier) arguments: (argument_list (identifier)))))))) |
static int isVowel ( char ch ) {
ch = Character . toUpperCase ( ch ) ;
if ( ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U' ) return 1 ;
else return 0 ;
}
| static int isVowel ( char ch ) { ch = Character . toUpperCase ( ch ) ; if ( ch == ' A ' || ch == ' E ' || ch == ' I ' || ch == ' O ' || ch == ' U ' ) return 1 ; else return 0 ; } | (method_declaration (modifiers) type: (integral_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (integral_type) name: (identifier))) body: (block (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))))) (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (binary_expression left: (binary_expression left: (binary_expression left: (identifier) right: (character_literal)) right: (binary_expression left: (identifier) right: (character_literal))) right: (binary_expression left: (identifier) right: (character_literal))) right: (binary_expression left: (identifier) right: (character_literal))) right: (binary_expression left: (identifier) right: (character_literal)))) consequence: (return_statement (decimal_integer_literal)) alternative: (return_statement (decimal_integer_literal))))) |
static int countVowels ( String str , int n ) {
if ( n == 1 ) return isVowel ( str . charAt ( n - 1 ) ) ;
return countVowels ( str , n - 1 ) + isVowel ( str . charAt ( n - 1 ) ) ;
}
| static int countVowels ( String str , int n ) { if ( n == 1 ) return isVowel ( str . charAt ( n - 1 ) ) ; return countVowels ( str , n - 1 ) + isVowel ( str . charAt ( n - 1 ) ) ; } | (method_declaration (modifiers) type: (integral_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (type_identifier) name: (identifier)) (formal_parameter type: (integral_type) name: (identifier))) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) consequence: (return_statement (method_invocation name: (identifier) arguments: (argument_list (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (binary_expression left: (identifier) right: (decimal_integer_literal)))))))) (return_statement (binary_expression left: (method_invocation name: (identifier) arguments: (argument_list (identifier) (binary_expression left: (identifier) right: (decimal_integer_literal)))) right: (method_invocation name: (identifier) arguments: (argument_list (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (binary_expression left: (identifier) right: (decimal_integer_literal)))))))))) |
public static void main ( String args [ ] ) {
String str = "abc de" ;
System . out . println ( countVowels ( str , str . length ( ) ) ) ;
}
| public static void main ( String args [ ] ) { String str = " abc β de " ; System . out . println ( countVowels ( str , str . length ( ) ) ) ; } | (method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (type_identifier) name: (identifier) dimensions: (dimensions))) body: (block (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (string_literal))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (method_invocation name: (identifier) arguments: (argument_list (identifier) (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))))))))) |
static void rgb_to_hsv ( double r , double g , double b ) {
r = r / 255.0 ;
g = g / 255.0 ;
b = b / 255.0 ;
double cmax = Math . max ( r , Math . max ( g , b ) ) ;
double cmin = Math . min ( r , Math . min ( g , b ) ) ;
double diff = cmax - cmin ;
double h = - 1 , s = - 1 ;
if ( cmax == cmin ) h = 0 ;
else if ( cmax == r ) h = ( 60 * ( ( g - b ) / diff ) + 360 ) % 360 ;
else if ( cmax == g ) h = ( 60 * ( ( b - r ) / diff ) + 120 ) % 360 ;
else if ( cmax == b ) h = ( 60 * ( ( r - g ) / diff ) + 240 ) % 360 ;
if ( cmax == 0 ) s = 0 ;
else s = ( diff / cmax ) * 100 ;
double v = cmax * 100 ;
System . out . println ( "(" + h + " " + s + " " + v + ")" ) ;
}
| static void rgb_to_hsv ( double r , double g , double b ) { r = r / 255.0 ; g = g / 255.0 ; b = b / 255.0 ; double cmax = Math . max ( r , Math . max ( g , b ) ) ; double cmin = Math . min ( r , Math . min ( g , b ) ) ; double diff = cmax - cmin ; double h = - 1 , s = - 1 ; if ( cmax == cmin ) h = 0 ; else if ( cmax == r ) h = ( 60 * ( ( g - b ) / diff ) + 360 ) % 360 ; else if ( cmax == g ) h = ( 60 * ( ( b - r ) / diff ) + 120 ) % 360 ; else if ( cmax == b ) h = ( 60 * ( ( r - g ) / diff ) + 240 ) % 360 ; if ( cmax == 0 ) s = 0 ; else s = ( diff / cmax ) * 100 ; double v = cmax * 100 ; System . out . println ( " ( " + h + " β " + s + " β " + v + " ) " ) ; } | (method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (floating_point_type) name: (identifier)) (formal_parameter type: (floating_point_type) name: (identifier)) (formal_parameter type: (floating_point_type) name: (identifier))) body: (block (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (identifier) right: (decimal_floating_point_literal)))) (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (identifier) right: (decimal_floating_point_literal)))) (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (identifier) right: (decimal_floating_point_literal)))) (local_variable_declaration type: (floating_point_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (identifier))))))) (local_variable_declaration type: (floating_point_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (identifier))))))) (local_variable_declaration type: (floating_point_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (identifier) right: (identifier)))) (local_variable_declaration type: (floating_point_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)))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) consequence: (expression_statement (assignment_expression left: (identifier) right: (decimal_integer_literal))) alternative: (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) consequence: (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (parenthesized_expression (binary_expression left: (binary_expression left: (decimal_integer_literal) right: (parenthesized_expression (binary_expression left: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) right: (identifier)))) right: (decimal_integer_literal))) right: (decimal_integer_literal)))) alternative: (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) consequence: (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (parenthesized_expression (binary_expression left: (binary_expression left: (decimal_integer_literal) right: (parenthesized_expression (binary_expression left: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) right: (identifier)))) right: (decimal_integer_literal))) right: (decimal_integer_literal)))) alternative: (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) consequence: (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (parenthesized_expression (binary_expression left: (binary_expression left: (decimal_integer_literal) right: (parenthesized_expression (binary_expression left: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) right: (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: (decimal_integer_literal))) alternative: (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) right: (decimal_integer_literal))))) (local_variable_declaration type: (floating_point_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (identifier) right: (decimal_integer_literal)))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (binary_expression left: (binary_expression left: (binary_expression left: (binary_expression left: (binary_expression left: (binary_expression left: (string_literal) right: (identifier)) right: (string_literal)) right: (identifier)) right: (string_literal)) right: (identifier)) right: (string_literal))))))) |
public static void main ( String [ ] args ) {
rgb_to_hsv ( 129 , 88 , 47 ) ;
}
| public static void main ( String [ ] args ) { rgb_to_hsv ( 129 , 88 , 47 ) ; } | (method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (array_type element: (type_identifier) dimensions: (dimensions)) name: (identifier))) body: (block (expression_statement (method_invocation name: (identifier) arguments: (argument_list (decimal_integer_literal) (decimal_integer_literal) (decimal_integer_literal)))))) |
static int flipBit ( int a ) {
if ( ~ a == 0 ) {
return 8 * sizeof ( ) ;
}
int currLen = 0 , prevLen = 0 , maxLen = 0 ;
while ( a != 0 ) {
if ( ( a & 1 ) == 1 ) {
currLen ++ ;
}
else if ( ( a & 1 ) == 0 ) {
prevLen = ( a & 2 ) == 0 ? 0 : currLen ;
currLen = 0 ;
}
maxLen = Math . max ( prevLen + currLen , maxLen ) ;
a >>= 1 ;
}
return maxLen + 1 ;
}
| static int flipBit ( int a ) { if ( ~ a == 0 ) { return 8 * sizeof ( ) ; } int currLen = 0 , prevLen = 0 , maxLen = 0 ; while ( a != 0 ) { if ( ( a & 1 ) == 1 ) { currLen ++ ; } else if ( ( a & 1 ) == 0 ) { prevLen = ( a & 2 ) == 0 ? 0 : currLen ; currLen = 0 ; } maxLen = Math . max ( prevLen + currLen , maxLen ) ; a >>= 1 ; } return maxLen + 1 ; } | (method_declaration (modifiers) type: (integral_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (integral_type) name: (identifier))) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (unary_expression operand: (identifier)) right: (decimal_integer_literal))) consequence: (block (return_statement (binary_expression left: (decimal_integer_literal) right: (method_invocation name: (identifier) arguments: (argument_list)))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal)) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal)) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (while_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) right: (decimal_integer_literal))) consequence: (block (expression_statement (update_expression (identifier)))) alternative: (if_statement condition: (parenthesized_expression (binary_expression left: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) right: (decimal_integer_literal))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (ternary_expression condition: (binary_expression left: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) right: (decimal_integer_literal)) consequence: (decimal_integer_literal) alternative: (identifier)))) (expression_statement (assignment_expression left: (identifier) right: (decimal_integer_literal)))))) (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (binary_expression left: (identifier) right: (identifier)) (identifier))))) (expression_statement (assignment_expression left: (identifier) right: (decimal_integer_literal))))) (return_statement (binary_expression left: (identifier) right: (decimal_integer_literal))))) |
static byte sizeof ( ) {
byte sizeOfInteger = 8 ;
return sizeOfInteger ;
}
| static byte sizeof ( ) { byte sizeOfInteger = 8 ; return sizeOfInteger ; } | (method_declaration (modifiers) type: (integral_type) name: (identifier) parameters: (formal_parameters) body: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (return_statement (identifier)))) |
public static void main ( String [ ] args ) {
System . out . println ( flipBit ( 13 ) ) ;
System . out . println ( flipBit ( 1775 ) ) ;
System . out . println ( flipBit ( 15 ) ) ;
}
| public static void main ( String [ ] args ) { System . out . println ( flipBit ( 13 ) ) ; System . out . println ( flipBit ( 1775 ) ) ; System . out . println ( flipBit ( 15 ) ) ; } | (method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (array_type element: (type_identifier) dimensions: (dimensions)) name: (identifier))) body: (block (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (method_invocation name: (identifier) arguments: (argument_list (decimal_integer_literal)))))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (method_invocation name: (identifier) arguments: (argument_list (decimal_integer_literal)))))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (method_invocation name: (identifier) arguments: (argument_list (decimal_integer_literal)))))))) |
static int longestSubarray ( int a [ ] , int n , int x ) {
int count = 0 ;
int length = 0 ;
for ( int i = 0 ;
i < n ;
i ++ ) {
if ( a [ i ] > x ) {
count += 1 ;
}
else {
length = Math . max ( length , count ) ;
count = 0 ;
}
}
if ( count > 0 ) length = Math . max ( length , count ) ;
return length ;
}
| static int longestSubarray ( int a [ ] , int n , int x ) { int count = 0 ; int length = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( a [ i ] > x ) { count += 1 ; } else { length = Math . max ( length , count ) ; count = 0 ; } } if ( count > 0 ) length = Math . max ( length , count ) ; return length ; } | (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))) (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: (identifier))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (decimal_integer_literal)))) alternative: (block (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (identifier))))) (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: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (identifier)))))) (return_statement (identifier)))) |
public static void main ( String [ ] args ) {
int [ ] a = {
8 , 25 , 10 , 19 , 19 , 18 , 20 , 11 , 18 };
int n = a . length ;
int k = 13 ;
System . out . println ( longestSubarray ( a , n , k ) ) ;
}
| public static void main ( String [ ] args ) { int [ ] a = { 8 , 25 , 10 , 19 , 19 , 18 , 20 , 11 , 18 } ; int n = a . length ; int k = 13 ; System . out . println ( longestSubarray ( a , n , k ) ) ; } | (method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (array_type element: (type_identifier) dimensions: (dimensions)) name: (identifier))) body: (block (local_variable_declaration type: (array_type element: (integral_type) dimensions: (dimensions)) declarator: (variable_declarator name: (identifier) value: (array_initializer (decimal_integer_literal) (decimal_integer_literal) (decimal_integer_literal) (decimal_integer_literal) (decimal_integer_literal) (decimal_integer_literal) (decimal_integer_literal) (decimal_integer_literal) (decimal_integer_literal)))) (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: (decimal_integer_literal))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (method_invocation name: (identifier) arguments: (argument_list (identifier) (identifier) (identifier)))))))) |
static int numberOfWays ( int x ) {
if ( x == 0 || x == 1 ) return 1 ;
else return numberOfWays ( x - 1 ) + ( x - 1 ) * numberOfWays ( x - 2 ) ;
}
| static int numberOfWays ( int x ) { if ( x == 0 || x == 1 ) return 1 ; else return numberOfWays ( x - 1 ) + ( x - 1 ) * numberOfWays ( x - 2 ) ; } | (method_declaration (modifiers) type: (integral_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (integral_type) name: (identifier))) body: (block (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 (decimal_integer_literal)) alternative: (return_statement (binary_expression left: (method_invocation name: (identifier) arguments: (argument_list (binary_expression left: (identifier) right: (decimal_integer_literal)))) right: (binary_expression left: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) right: (method_invocation name: (identifier) arguments: (argument_list (binary_expression left: (identifier) right: (decimal_integer_literal)))))))))) |
public static void main ( String [ ] args ) {
int x = 3 ;
System . out . println ( numberOfWays ( x ) ) ;
}
| public static void main ( String [ ] args ) { int x = 3 ; System . out . println ( numberOfWays ( x ) ) ; } | (method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (array_type element: (type_identifier) dimensions: (dimensions)) name: (identifier))) body: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (method_invocation name: (identifier) arguments: (argument_list (identifier)))))))) |
static String commonPrefixUtil ( String str1 , String str2 ) {
String result = "" ;
int n1 = str1 . length ( ) , n2 = str2 . length ( ) ;
for ( int i = 0 , j = 0 ;
i <= n1 - 1 && j <= n2 - 1 ;
i ++ , j ++ ) {
if ( str1 . charAt ( i ) != str2 . charAt ( j ) ) {
break ;
}
result += str1 . charAt ( i ) ;
}
return ( result ) ;
}
| static String commonPrefixUtil ( String str1 , String str2 ) { String result = " " ; int n1 = str1 . length ( ) , n2 = str2 . length ( ) ; for ( int i = 0 , j = 0 ; i <= n1 - 1 && j <= n2 - 1 ; i ++ , j ++ ) { if ( str1 . charAt ( i ) != str2 . charAt ( j ) ) { break ; } result += str1 . charAt ( i ) ; } return ( result ) ; } | (method_declaration (modifiers) type: (type_identifier) name: (identifier) parameters: (formal_parameters (formal_parameter type: (type_identifier) name: (identifier)) (formal_parameter type: (type_identifier) name: (identifier))) body: (block (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (string_literal))) (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: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal)) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) condition: (binary_expression left: (binary_expression left: (identifier) right: (binary_expression left: (identifier) right: (decimal_integer_literal))) right: (binary_expression left: (identifier) right: (binary_expression left: (identifier) right: (decimal_integer_literal)))) update: (update_expression (identifier)) update: (update_expression (identifier)) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))))) consequence: (block (break_statement))) (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))))))) (return_statement (parenthesized_expression (identifier))))) |
static String commonPrefix ( String arr [ ] , int n ) {
String prefix = arr [ 0 ] ;
for ( int i = 1 ;
i <= n - 1 ;
i ++ ) {
prefix = commonPrefixUtil ( prefix , arr [ i ] ) ;
}
return ( prefix ) ;
}
| static String commonPrefix ( String arr [ ] , int n ) { String prefix = arr [ 0 ] ; for ( int i = 1 ; i <= n - 1 ; i ++ ) { prefix = commonPrefixUtil ( prefix , arr [ i ] ) ; } return ( prefix ) ; } | (method_declaration (modifiers) type: (type_identifier) name: (identifier) parameters: (formal_parameters (formal_parameter type: (type_identifier) name: (identifier) dimensions: (dimensions)) (formal_parameter type: (integral_type) name: (identifier))) body: (block (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (array_access array: (identifier) index: (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: (binary_expression left: (identifier) right: (decimal_integer_literal))) update: (update_expression (identifier)) body: (block (expression_statement (assignment_expression left: (identifier) right: (method_invocation name: (identifier) arguments: (argument_list (identifier) (array_access array: (identifier) index: (identifier)))))))) (return_statement (parenthesized_expression (identifier))))) |
public static void main ( String [ ] args ) {
String arr [ ] = {
"geeksforgeeks" , "geeks" , "geek" , "geezer" };
int n = arr . length ;
String ans = commonPrefix ( arr , n ) ;
if ( ans . length ( ) > 0 ) {
System . out . printf ( "The longest common prefix is - %s" , ans ) ;
}
else {
System . out . printf ( "There is no common prefix" ) ;
}
}
| public static void main ( String [ ] args ) { String arr [ ] = { " geeksforgeeks " , " geeks " , " geek " , " geezer " } ; int n = arr . length ; String ans = commonPrefix ( arr , n ) ; if ( ans . length ( ) > 0 ) { System . out . printf ( " The β longest β common β prefix β is β - β % s " , ans ) ; } else { System . out . printf ( " There β is β no β common β prefix " ) ; } } | (method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (array_type element: (type_identifier) dimensions: (dimensions)) name: (identifier))) body: (block (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) dimensions: (dimensions) value: (array_initializer (string_literal) (string_literal) (string_literal) (string_literal)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (field_access object: (identifier) field: (identifier)))) (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (method_invocation name: (identifier) arguments: (argument_list (identifier) (identifier))))) (if_statement condition: (parenthesized_expression (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)) right: (decimal_integer_literal))) consequence: (block (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (string_literal) (identifier))))) alternative: (block (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (string_literal)))))))) |
public static void main ( String args [ ] ) {
GFG g = new GFG ( ) ;
int N = 5 ;
System . out . println ( g . CountDigits ( N ) ) ;
}
| public static void main ( String args [ ] ) { GFG g = new GFG ( ) ; int N = 5 ; System . out . println ( g . CountDigits ( N ) ) ; } | (method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (type_identifier) name: (identifier) dimensions: (dimensions))) body: (block (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (object_creation_expression type: (type_identifier) arguments: (argument_list)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))))))) |
static void printEgyptian ( int nr , int dr ) {
if ( dr == 0 || nr == 0 ) {
return ;
}
if ( dr % nr == 0 ) {
System . out . print ( "1/" + dr / nr ) ;
return ;
}
if ( nr % dr == 0 ) {
System . out . print ( nr / dr ) ;
return ;
}
if ( nr > dr ) {
System . out . print ( nr / dr + " + " ) ;
printEgyptian ( nr % dr , dr ) ;
return ;
}
int n = dr / nr + 1 ;
System . out . print ( "1/" + n + " + " ) ;
printEgyptian ( nr * n - dr , dr * n ) ;
}
| static void printEgyptian ( int nr , int dr ) { if ( dr == 0 || nr == 0 ) { return ; } if ( dr % nr == 0 ) { System . out . print ( "1 / " + dr / nr ) ; return ; } if ( nr % dr == 0 ) { System . out . print ( nr / dr ) ; return ; } if ( nr > dr ) { System . out . print ( nr / dr + " β + β " ) ; printEgyptian ( nr % dr , dr ) ; return ; } int n = dr / nr + 1 ; System . out . print ( "1 / " + n + " β + β " ) ; printEgyptian ( nr * n - dr , dr * n ) ; } | (method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (integral_type) name: (identifier)) (formal_parameter type: (integral_type) name: (identifier))) body: (block (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: (block (return_statement))) (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (identifier) right: (identifier)) right: (decimal_integer_literal))) consequence: (block (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (binary_expression left: (string_literal) right: (binary_expression left: (identifier) right: (identifier)))))) (return_statement))) (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (identifier) right: (identifier)) right: (decimal_integer_literal))) consequence: (block (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (binary_expression left: (identifier) right: (identifier))))) (return_statement))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) consequence: (block (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (binary_expression left: (binary_expression left: (identifier) right: (identifier)) right: (string_literal))))) (expression_statement (method_invocation name: (identifier) arguments: (argument_list (binary_expression left: (identifier) right: (identifier)) (identifier)))) (return_statement))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (binary_expression left: (identifier) right: (identifier)) right: (decimal_integer_literal)))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (binary_expression left: (binary_expression left: (string_literal) right: (identifier)) right: (string_literal))))) (expression_statement (method_invocation name: (identifier) arguments: (argument_list (binary_expression left: (binary_expression left: (identifier) right: (identifier)) right: (identifier)) (binary_expression left: (identifier) right: (identifier))))))) |
public static void main ( String [ ] args ) {
int nr = 6 , dr = 14 ;
System . out . print ( "Egyptian Fraction Representation of " + nr + "/" + dr + " is\n " ) ;
printEgyptian ( nr , dr ) ;
}
| public static void main ( String [ ] args ) { int nr = 6 , dr = 14 ; System . out . print ( " Egyptian β Fraction β Representation β of β " + nr + " / " + dr + " β is \n β " ) ; printEgyptian ( nr , dr ) ; } | (method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (array_type element: (type_identifier) dimensions: (dimensions)) 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))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (binary_expression left: (binary_expression left: (binary_expression left: (binary_expression left: (string_literal) right: (identifier)) right: (string_literal)) right: (identifier)) right: (string_literal))))) (expression_statement (method_invocation name: (identifier) arguments: (argument_list (identifier) (identifier)))))) |
public static double sumOfTheSeries ( int n ) {
double sum = 0.0 ;
for ( int i = 1 ;
i <= n ;
i ++ ) sum += 1.0 / ( i * ( i + 1 ) ) ;
return sum ;
}
| public static double sumOfTheSeries ( int n ) { double sum = 0.0 ; for ( int i = 1 ; i <= n ; i ++ ) sum += 1.0 / ( i * ( i + 1 ) ) ; return sum ; } | (method_declaration (modifiers) type: (floating_point_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (integral_type) name: (identifier))) body: (block (local_variable_declaration type: (floating_point_type) declarator: (variable_declarator name: (identifier) value: (decimal_floating_point_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: (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (decimal_floating_point_literal) right: (parenthesized_expression (binary_expression left: (identifier) right: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))))))))) (return_statement (identifier)))) |
public static void main ( String args [ ] ) {
int n = 10 ;
System . out . println ( sumOfTheSeries ( n ) ) ;
}
| public static void main ( String args [ ] ) { int n = 10 ; System . out . println ( sumOfTheSeries ( n ) ) ; } | (method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (type_identifier) name: (identifier) dimensions: (dimensions))) body: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (method_invocation name: (identifier) arguments: (argument_list (identifier)))))))) |
static void find_max ( int [ ] A , int N , int K ) {
HashMap < Integer , Integer > Count = new HashMap < > ( ) ;
for ( int i = 0 ;
i < K - 1 ;
i ++ ) if ( Count . containsKey ( A [ i ] ) ) Count . put ( A [ i ] , 1 + Count . get ( A [ i ] ) ) ;
else Count . put ( A [ i ] , 1 ) ;
TreeSet < Integer > Myset = new TreeSet < Integer > ( ) ;
for ( Map . Entry x : Count . entrySet ( ) ) {
if ( Integer . parseInt ( String . valueOf ( x . getValue ( ) ) ) == 1 ) Myset . add ( Integer . parseInt ( String . valueOf ( x . getKey ( ) ) ) ) ;
}
for ( int i = K - 1 ;
i < N ;
i ++ ) {
if ( Count . containsKey ( A [ i ] ) ) Count . put ( A [ i ] , 1 + Count . get ( A [ i ] ) ) ;
else Count . put ( A [ i ] , 1 ) ;
if ( Integer . parseInt ( String . valueOf ( Count . get ( A [ i ] ) ) ) == 1 ) Myset . add ( A [ i ] ) ;
else Myset . remove ( A [ i ] ) ;
if ( Myset . size ( ) == 0 ) System . out . println ( "Nothing" ) ;
else System . out . println ( Myset . last ( ) ) ;
int x = A [ i - K + 1 ] ;
Count . put ( x , Count . get ( x ) - 1 ) ;
if ( Integer . parseInt ( String . valueOf ( Count . get ( x ) ) ) == 1 ) Myset . add ( x ) ;
if ( Integer . parseInt ( String . valueOf ( Count . get ( x ) ) ) == 0 ) Myset . remove ( x ) ;
}
}
| static void find_max ( int [ ] A , int N , int K ) { HashMap < Integer , Integer > Count = new HashMap < > ( ) ; for ( int i = 0 ; i < K - 1 ; i ++ ) if ( Count . containsKey ( A [ i ] ) ) Count . put ( A [ i ] , 1 + Count . get ( A [ i ] ) ) ; else Count . put ( A [ i ] , 1 ) ; TreeSet < Integer > Myset = new TreeSet < Integer > ( ) ; for ( Map . Entry x : Count . entrySet ( ) ) { if ( Integer . parseInt ( String . valueOf ( x . getValue ( ) ) ) == 1 ) Myset . add ( Integer . parseInt ( String . valueOf ( x . getKey ( ) ) ) ) ; } for ( int i = K - 1 ; i < N ; i ++ ) { if ( Count . containsKey ( A [ i ] ) ) Count . put ( A [ i ] , 1 + Count . get ( A [ i ] ) ) ; else Count . put ( A [ i ] , 1 ) ; if ( Integer . parseInt ( String . valueOf ( Count . get ( A [ i ] ) ) ) == 1 ) Myset . add ( A [ i ] ) ; else Myset . remove ( A [ i ] ) ; if ( Myset . size ( ) == 0 ) System . out . println ( " Nothing " ) ; else System . out . println ( Myset . last ( ) ) ; int x = A [ i - K + 1 ] ; Count . put ( x , Count . get ( x ) - 1 ) ; if ( Integer . parseInt ( String . valueOf ( Count . get ( x ) ) ) == 1 ) Myset . add ( x ) ; if ( Integer . parseInt ( String . valueOf ( Count . get ( x ) ) ) == 0 ) Myset . remove ( x ) ; } } | (method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (array_type element: (integral_type) dimensions: (dimensions)) name: (identifier)) (formal_parameter type: (integral_type) name: (identifier)) (formal_parameter type: (integral_type) name: (identifier))) body: (block (local_variable_declaration type: (generic_type (type_identifier) (type_arguments (type_identifier) (type_identifier))) declarator: (variable_declarator name: (identifier) value: (object_creation_expression type: (generic_type (type_identifier) (type_arguments)) arguments: (argument_list)))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) condition: (binary_expression left: (identifier) right: (binary_expression left: (identifier) right: (decimal_integer_literal))) update: (update_expression (identifier)) body: (if_statement condition: (parenthesized_expression (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (array_access array: (identifier) index: (identifier))))) consequence: (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (array_access array: (identifier) index: (identifier)) (binary_expression left: (decimal_integer_literal) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (array_access array: (identifier) index: (identifier)))))))) alternative: (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (array_access array: (identifier) index: (identifier)) (decimal_integer_literal)))))) (local_variable_declaration type: (generic_type (type_identifier) (type_arguments (type_identifier))) declarator: (variable_declarator name: (identifier) value: (object_creation_expression type: (generic_type (type_identifier) (type_arguments (type_identifier))) arguments: (argument_list)))) (enhanced_for_statement type: (scoped_type_identifier (type_identifier) (type_identifier)) name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))))) right: (decimal_integer_literal))) consequence: (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))))))))))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (identifier) right: (decimal_integer_literal)))) condition: (binary_expression left: (identifier) right: (identifier)) update: (update_expression (identifier)) body: (block (if_statement condition: (parenthesized_expression (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (array_access array: (identifier) index: (identifier))))) consequence: (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (array_access array: (identifier) index: (identifier)) (binary_expression left: (decimal_integer_literal) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (array_access array: (identifier) index: (identifier)))))))) alternative: (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (array_access array: (identifier) index: (identifier)) (decimal_integer_literal))))) (if_statement condition: (parenthesized_expression (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (array_access array: (identifier) index: (identifier)))))))) right: (decimal_integer_literal))) consequence: (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (array_access array: (identifier) index: (identifier))))) alternative: (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (array_access array: (identifier) index: (identifier)))))) (if_statement condition: (parenthesized_expression (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)) right: (decimal_integer_literal))) 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 (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (array_access array: (identifier) index: (binary_expression left: (binary_expression left: (identifier) right: (identifier)) right: (decimal_integer_literal))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))) right: (decimal_integer_literal))))) (if_statement condition: (parenthesized_expression (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))))))) right: (decimal_integer_literal))) consequence: (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))))) (if_statement condition: (parenthesized_expression (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))))))) right: (decimal_integer_literal))) consequence: (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))))))))) |
public static void main ( String args [ ] ) {
int [ ] a = {
1 , 2 , 2 , 3 , 3 };
int n = a . length ;
int k = 3 ;
find_max ( a , n , k ) ;
}
| public static void main ( String args [ ] ) { int [ ] a = { 1 , 2 , 2 , 3 , 3 } ; int n = a . length ; int k = 3 ; find_max ( a , n , k ) ; } | (method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (type_identifier) name: (identifier) dimensions: (dimensions))) body: (block (local_variable_declaration type: (array_type element: (integral_type) dimensions: (dimensions)) declarator: (variable_declarator name: (identifier) value: (array_initializer (decimal_integer_literal) (decimal_integer_literal) (decimal_integer_literal) (decimal_integer_literal) (decimal_integer_literal)))) (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: (decimal_integer_literal))) (expression_statement (method_invocation name: (identifier) arguments: (argument_list (identifier) (identifier) (identifier)))))) |
static int NthPrime ( int n ) {
int count = 0 ;
int i ;
for ( i = 2 ;
i <= MAX ;
i ++ ) {
int check = 0 ;
for ( int j = 2 ;
j <= Math . sqrt ( i ) ;
j ++ ) {
if ( i % j == 0 ) {
check = 1 ;
break ;
}
}
if ( check == 0 ) count ++ ;
if ( count == n ) {
return i ;
}
}
return 0 ;
}
| static int NthPrime ( int n ) { int count = 0 ; int i ; for ( i = 2 ; i <= MAX ; i ++ ) { int check = 0 ; for ( int j = 2 ; j <= Math . sqrt ( i ) ; j ++ ) { if ( i % j == 0 ) { check = 1 ; break ; } } if ( check == 0 ) count ++ ; if ( count == n ) { return i ; } } return 0 ; } | (method_declaration (modifiers) type: (integral_type) name: (identifier) parameters: (formal_parameters (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))) (for_statement init: (assignment_expression left: (identifier) right: (decimal_integer_literal)) condition: (binary_expression left: (identifier) right: (identifier)) update: (update_expression (identifier)) body: (block (local_variable_declaration type: (integral_type) 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: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))) update: (update_expression (identifier)) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (identifier) right: (identifier)) right: (decimal_integer_literal))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (decimal_integer_literal))) (break_statement))))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) consequence: (expression_statement (update_expression (identifier)))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) consequence: (block (return_statement (identifier)))))) (return_statement (decimal_integer_literal)))) |
static int NthFib ( int n ) {
int [ ] f = new int [ n + 2 ] ;
int i ;
f [ 0 ] = 0 ;
f [ 1 ] = 1 ;
for ( i = 2 ;
i <= n ;
i ++ ) {
f [ i ] = f [ i - 1 ] + f [ i - 2 ] ;
}
return f [ n ] ;
}
| static int NthFib ( int n ) { int [ ] f = new int [ n + 2 ] ; int i ; f [ 0 ] = 0 ; f [ 1 ] = 1 ; for ( i = 2 ; i <= n ; i ++ ) { f [ i ] = f [ i - 1 ] + f [ i - 2 ] ; } return f [ n ] ; } | (method_declaration (modifiers) type: (integral_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (integral_type) name: (identifier))) body: (block (local_variable_declaration type: (array_type element: (integral_type) dimensions: (dimensions)) declarator: (variable_declarator name: (identifier) value: (array_creation_expression type: (integral_type) dimensions: (dimensions_expr (binary_expression left: (identifier) right: (decimal_integer_literal)))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier))) (expression_statement (assignment_expression left: (array_access array: (identifier) index: (decimal_integer_literal)) right: (decimal_integer_literal))) (expression_statement (assignment_expression left: (array_access array: (identifier) index: (decimal_integer_literal)) right: (decimal_integer_literal))) (for_statement init: (assignment_expression left: (identifier) right: (decimal_integer_literal)) condition: (binary_expression left: (identifier) right: (identifier)) update: (update_expression (identifier)) body: (block (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (binary_expression left: (array_access array: (identifier) index: (binary_expression left: (identifier) right: (decimal_integer_literal))) right: (array_access array: (identifier) index: (binary_expression left: (identifier) right: (decimal_integer_literal)))))))) (return_statement (array_access array: (identifier) index: (identifier))))) |
static void findNthTerm ( int n ) {
if ( n % 2 == 0 ) {
n = n / 2 ;
n = NthPrime ( n ) ;
System . out . println ( n ) ;
}
else {
n = ( n / 2 ) + 1 ;
n = NthFib ( n - 1 ) ;
System . out . println ( n ) ;
}
}
| static void findNthTerm ( int n ) { if ( n % 2 == 0 ) { n = n / 2 ; n = NthPrime ( n ) ; System . out . println ( n ) ; } else { n = ( n / 2 ) + 1 ; n = NthFib ( n - 1 ) ; System . out . println ( n ) ; } } | (method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (integral_type) name: (identifier))) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (identifier) right: (decimal_integer_literal)) right: (decimal_integer_literal))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (identifier) right: (decimal_integer_literal)))) (expression_statement (assignment_expression left: (identifier) right: (method_invocation name: (identifier) arguments: (argument_list (identifier))))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (identifier))))) alternative: (block (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) right: (decimal_integer_literal)))) (expression_statement (assignment_expression left: (identifier) right: (method_invocation name: (identifier) arguments: (argument_list (binary_expression left: (identifier) right: (decimal_integer_literal)))))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (identifier)))))))) |
public static void main ( String [ ] args ) {
int X = 5 ;
findNthTerm ( X ) ;
X = 10 ;
findNthTerm ( X ) ;
}
| public static void main ( String [ ] args ) { int X = 5 ; findNthTerm ( X ) ; X = 10 ; findNthTerm ( X ) ; } | (method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (array_type element: (type_identifier) dimensions: (dimensions)) name: (identifier))) body: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (expression_statement (method_invocation name: (identifier) arguments: (argument_list (identifier)))) (expression_statement (assignment_expression left: (identifier) right: (decimal_integer_literal))) (expression_statement (method_invocation name: (identifier) arguments: (argument_list (identifier)))))) |
static boolean checkYear ( int year ) {
return ( ( ( year % 4 == 0 ) && ( year % 100 != 0 ) ) || ( year % 400 == 0 ) ) ;
}
| static boolean checkYear ( int year ) { return ( ( ( year % 4 == 0 ) && ( year % 100 != 0 ) ) || ( year % 400 == 0 ) ) ; } | (method_declaration (modifiers) type: (boolean_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (integral_type) name: (identifier))) body: (block (return_statement (parenthesized_expression (binary_expression left: (parenthesized_expression (binary_expression left: (parenthesized_expression (binary_expression left: (binary_expression left: (identifier) right: (decimal_integer_literal)) right: (decimal_integer_literal))) right: (parenthesized_expression (binary_expression left: (binary_expression left: (identifier) right: (decimal_integer_literal)) right: (decimal_integer_literal))))) right: (parenthesized_expression (binary_expression left: (binary_expression left: (identifier) right: (decimal_integer_literal)) right: (decimal_integer_literal)))))))) |
public static void main ( String [ ] args ) {
int year = 2000 ;
System . out . println ( checkYear ( 2000 ) ? "Leap Year" : "Not a Leap Year" ) ;
}
| public static void main ( String [ ] args ) { int year = 2000 ; System . out . println ( checkYear ( 2000 ) ? " Leap β Year " : " Not β a β Leap β Year " ) ; } | (method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (array_type element: (type_identifier) dimensions: (dimensions)) name: (identifier))) body: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (ternary_expression condition: (method_invocation name: (identifier) arguments: (argument_list (decimal_integer_literal))) consequence: (string_literal) alternative: (string_literal))))))) |
static void twoParts ( String str ) {
int flag = 0 ;
String a = "" ;
char [ ] gfg = str . toCharArray ( ) ;
for ( int i = 0 ;
i < str . length ( ) ;
i ++ ) {
if ( gfg [ i ] == '4' ) {
gfg [ i ] = '3' ;
a += '1' ;
flag = 1 ;
}
else if ( flag != 0 ) a += '0' ;
}
str = new String ( gfg ) ;
System . out . print ( str + " " + a ) ;
}
| static void twoParts ( String str ) { int flag = 0 ; String a = " " ; char [ ] gfg = str . toCharArray ( ) ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) { if ( gfg [ i ] == '4' ) { gfg [ i ] = '3' ; a += '1' ; flag = 1 ; } else if ( flag != 0 ) a += '0' ; } str = new String ( gfg ) ; System . out . print ( str + " β " + a ) ; } | (method_declaration (modifiers) type: (void_type) 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: (decimal_integer_literal))) (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (string_literal))) (local_variable_declaration type: (array_type element: (integral_type) dimensions: (dimensions)) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) condition: (binary_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))) update: (update_expression (identifier)) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (character_literal))) consequence: (block (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (character_literal))) (expression_statement (assignment_expression left: (identifier) right: (character_literal))) (expression_statement (assignment_expression left: (identifier) right: (decimal_integer_literal)))) alternative: (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) consequence: (expression_statement (assignment_expression left: (identifier) right: (character_literal))))))) (expression_statement (assignment_expression left: (identifier) right: (object_creation_expression type: (type_identifier) arguments: (argument_list (identifier))))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (binary_expression left: (binary_expression left: (identifier) right: (string_literal)) right: (identifier))))))) |
public static void main ( String [ ] args ) {
String str = "9441" ;
twoParts ( str ) ;
}
| public static void main ( String [ ] args ) { String str = "9441" ; twoParts ( str ) ; } | (method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (array_type element: (type_identifier) dimensions: (dimensions)) name: (identifier))) body: (block (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (string_literal))) (expression_statement (method_invocation name: (identifier) arguments: (argument_list (identifier)))))) |
static int lcs ( String X , String Y , int m , int n ) {
int L [ ] [ ] = new int [ m + 1 ] [ n + 1 ] ;
for ( int i = 0 ;
i <= m ;
i ++ ) {
for ( int j = 0 ;
j <= n ;
j ++ ) {
if ( i == 0 || j == 0 ) L [ i ] [ j ] = 0 ;
else if ( X . charAt ( i - 1 ) == Y . charAt ( j - 1 ) ) L [ i ] [ j ] = L [ i - 1 ] [ j - 1 ] + 1 ;
else L [ i ] [ j ] = Math . max ( L [ i - 1 ] [ j ] , L [ i ] [ j - 1 ] ) ;
}
}
return L [ m ] [ n ] ;
}
| static int lcs ( String X , String Y , int m , int n ) { int L [ ] [ ] = new int [ m + 1 ] [ n + 1 ] ; for ( int i = 0 ; i <= m ; i ++ ) { for ( int j = 0 ; j <= n ; j ++ ) { if ( i == 0 || j == 0 ) L [ i ] [ j ] = 0 ; else if ( X . charAt ( i - 1 ) == Y . charAt ( j - 1 ) ) L [ i ] [ j ] = L [ i - 1 ] [ j - 1 ] + 1 ; else L [ i ] [ j ] = Math . max ( L [ i - 1 ] [ j ] , L [ i ] [ j - 1 ] ) ; } } return L [ m ] [ n ] ; } | (method_declaration (modifiers) type: (integral_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (type_identifier) name: (identifier)) (formal_parameter type: (type_identifier) name: (identifier)) (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) dimensions: (dimensions) value: (array_creation_expression type: (integral_type) dimensions: (dimensions_expr (binary_expression left: (identifier) right: (decimal_integer_literal))) dimensions: (dimensions_expr (binary_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 (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: (identifier) right: (decimal_integer_literal)) right: (binary_expression left: (identifier) right: (decimal_integer_literal)))) consequence: (expression_statement (assignment_expression left: (array_access array: (array_access array: (identifier) index: (identifier)) index: (identifier)) right: (decimal_integer_literal))) 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: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (binary_expression left: (identifier) right: (decimal_integer_literal)))))) consequence: (expression_statement (assignment_expression left: (array_access array: (array_access array: (identifier) index: (identifier)) index: (identifier)) right: (binary_expression left: (array_access array: (array_access array: (identifier) index: (binary_expression left: (identifier) right: (decimal_integer_literal))) index: (binary_expression left: (identifier) right: (decimal_integer_literal))) right: (decimal_integer_literal)))) alternative: (expression_statement (assignment_expression left: (array_access array: (array_access array: (identifier) index: (identifier)) index: (identifier)) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (array_access array: (array_access array: (identifier) index: (binary_expression left: (identifier) right: (decimal_integer_literal))) index: (identifier)) (array_access array: (array_access array: (identifier) index: (identifier)) index: (binary_expression left: (identifier) right: (decimal_integer_literal))))))))))))) (return_statement (array_access array: (array_access array: (identifier) index: (identifier)) index: (identifier))))) |
static int findMinCost ( String X , String Y , int costX , int costY ) {
int m = X . length ( ) ;
int n = Y . length ( ) ;
int len_LCS ;
len_LCS = lcs ( X , Y , m , n ) ;
return costX * ( m - len_LCS ) + costY * ( n - len_LCS ) ;
}
| static int findMinCost ( String X , String Y , int costX , int costY ) { int m = X . length ( ) ; int n = Y . length ( ) ; int len_LCS ; len_LCS = lcs ( X , Y , m , n ) ; return costX * ( m - len_LCS ) + costY * ( n - len_LCS ) ; } | (method_declaration (modifiers) type: (integral_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (type_identifier) name: (identifier)) (formal_parameter type: (type_identifier) name: (identifier)) (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: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier))) (expression_statement (assignment_expression left: (identifier) right: (method_invocation name: (identifier) arguments: (argument_list (identifier) (identifier) (identifier) (identifier))))) (return_statement (binary_expression left: (binary_expression left: (identifier) right: (parenthesized_expression (binary_expression left: (identifier) right: (identifier)))) right: (binary_expression left: (identifier) right: (parenthesized_expression (binary_expression left: (identifier) right: (identifier)))))))) |
public static void main ( String [ ] args ) {
String X = "ef" ;
String Y = "gh" ;
System . out . println ( "Minimum Cost to make two strings " + " identical is = " + findMinCost ( X , Y , 10 , 20 ) ) ;
}
| public static void main ( String [ ] args ) { String X = " ef " ; String Y = " gh " ; System . out . println ( " Minimum β Cost β to β make β two β strings β " + " β identical β is β = β " + findMinCost ( X , Y , 10 , 20 ) ) ; } | (method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (array_type element: (type_identifier) dimensions: (dimensions)) name: (identifier))) body: (block (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (string_literal))) (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (string_literal))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (binary_expression left: (binary_expression left: (string_literal) right: (string_literal)) right: (method_invocation name: (identifier) arguments: (argument_list (identifier) (identifier) (decimal_integer_literal) (decimal_integer_literal))))))))) |
static double calculate_angle ( int n , int i , int j , int k ) {
int x , y ;
if ( i < j ) x = j - i ;
else x = j + n - i ;
if ( j < k ) y = k - j ;
else y = k + n - j ;
double ang1 = ( 180 * x ) / n ;
double ang2 = ( 180 * y ) / n ;
double ans = 180 - ang1 - ang2 ;
return ans ;
}
| static double calculate_angle ( int n , int i , int j , int k ) { int x , y ; if ( i < j ) x = j - i ; else x = j + n - i ; if ( j < k ) y = k - j ; else y = k + n - j ; double ang1 = ( 180 * x ) / n ; double ang2 = ( 180 * y ) / n ; double ans = 180 - ang1 - ang2 ; return ans ; } | (method_declaration (modifiers) type: (floating_point_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (integral_type) name: (identifier)) (formal_parameter type: (integral_type) name: (identifier)) (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)) declarator: (variable_declarator name: (identifier))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) consequence: (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (identifier) right: (identifier)))) alternative: (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (binary_expression left: (identifier) right: (identifier)) right: (identifier))))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) consequence: (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (identifier) right: (identifier)))) alternative: (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (binary_expression left: (identifier) right: (identifier)) right: (identifier))))) (local_variable_declaration type: (floating_point_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (parenthesized_expression (binary_expression left: (decimal_integer_literal) right: (identifier))) right: (identifier)))) (local_variable_declaration type: (floating_point_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (parenthesized_expression (binary_expression left: (decimal_integer_literal) right: (identifier))) right: (identifier)))) (local_variable_declaration type: (floating_point_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (binary_expression left: (decimal_integer_literal) right: (identifier)) right: (identifier)))) (return_statement (identifier)))) |
public static void main ( String [ ] args ) {
int n = 5 ;
int a1 = 1 ;
int a2 = 2 ;
int a3 = 5 ;
System . out . println ( ( int ) calculate_angle ( n , a1 , a2 , a3 ) ) ;
}
| public static void main ( String [ ] args ) { int n = 5 ; int a1 = 1 ; int a2 = 2 ; int a3 = 5 ; System . out . println ( ( int ) calculate_angle ( n , a1 , a2 , a3 ) ) ; } | (method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (array_type element: (type_identifier) dimensions: (dimensions)) 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: (decimal_integer_literal))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (cast_expression type: (integral_type) value: (method_invocation name: (identifier) arguments: (argument_list (identifier) (identifier) (identifier) (identifier))))))))) |
static int countPairs ( int arr [ ] , int k ) {
Arrays . sort ( arr ) ;
int pair = 0 ;
int index = 0 ;
while ( index < arr . length - 1 ) {
if ( arr [ index + 1 ] - arr [ index ] <= k ) {
pair += 1 ;
index += 2 ;
}
else {
index += 1 ;
}
}
return pair ;
}
| static int countPairs ( int arr [ ] , int k ) { Arrays . sort ( arr ) ; int pair = 0 ; int index = 0 ; while ( index < arr . length - 1 ) { if ( arr [ index + 1 ] - arr [ index ] <= k ) { pair += 1 ; index += 2 ; } else { index += 1 ; } } return pair ; } | (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))) body: (block (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))) (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))) (while_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (binary_expression left: (field_access object: (identifier) field: (identifier)) right: (decimal_integer_literal)))) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (array_access array: (identifier) index: (binary_expression left: (identifier) right: (decimal_integer_literal))) right: (array_access array: (identifier) index: (identifier))) right: (identifier))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (decimal_integer_literal))) (expression_statement (assignment_expression left: (identifier) right: (decimal_integer_literal)))) alternative: (block (expression_statement (assignment_expression left: (identifier) right: (decimal_integer_literal))))))) (return_statement (identifier)))) |
public static void main ( String [ ] args ) {
int arr [ ] = {
1 , 4 , 3 , 7 , 5 };
int k = 2 ;
int count = countPairs ( arr , k ) ;
System . out . println ( count ) ;
}
| public static void main ( String [ ] args ) { int arr [ ] = { 1 , 4 , 3 , 7 , 5 } ; int k = 2 ; int count = countPairs ( arr , k ) ; System . out . println ( count ) ; } | (method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (array_type element: (type_identifier) dimensions: (dimensions)) name: (identifier))) body: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) dimensions: (dimensions) value: (array_initializer (decimal_integer_literal) (decimal_integer_literal) (decimal_integer_literal) (decimal_integer_literal) (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: (method_invocation name: (identifier) arguments: (argument_list (identifier) (identifier))))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (identifier)))))) |
static void leftRotate ( int arr [ ] , int n , int k ) {
for ( int i = k ;
i < k + n ;
i ++ ) System . out . print ( arr [ i % n ] + " " ) ;
}
| static void leftRotate ( int arr [ ] , int n , int k ) { for ( int i = k ; i < k + n ; i ++ ) System . out . print ( arr [ i % n ] + " β " ) ; } | (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)) (formal_parameter type: (integral_type) name: (identifier))) body: (block (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (identifier))) condition: (binary_expression left: (identifier) right: (binary_expression left: (identifier) right: (identifier))) update: (update_expression (identifier)) body: (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (binary_expression left: (array_access array: (identifier) index: (binary_expression left: (identifier) right: (identifier))) right: (string_literal)))))))) |
public static void main ( String [ ] args ) {
int arr [ ] = {
1 , 3 , 5 , 7 , 9 };
int n = arr . length ;
int k = 2 ;
leftRotate ( arr , n , k ) ;
System . out . println ( ) ;
k = 3 ;
leftRotate ( arr , n , k ) ;
System . out . println ( ) ;
k = 4 ;
leftRotate ( arr , n , k ) ;
System . out . println ( ) ;
}
| public static void main ( String [ ] args ) { int arr [ ] = { 1 , 3 , 5 , 7 , 9 } ; int n = arr . length ; int k = 2 ; leftRotate ( arr , n , k ) ; System . out . println ( ) ; k = 3 ; leftRotate ( arr , n , k ) ; System . out . println ( ) ; k = 4 ; leftRotate ( arr , n , k ) ; System . out . println ( ) ; } | (method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (array_type element: (type_identifier) dimensions: (dimensions)) name: (identifier))) body: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) dimensions: (dimensions) value: (array_initializer (decimal_integer_literal) (decimal_integer_literal) (decimal_integer_literal) (decimal_integer_literal) (decimal_integer_literal)))) (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: (decimal_integer_literal))) (expression_statement (method_invocation name: (identifier) arguments: (argument_list (identifier) (identifier) (identifier)))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list))) (expression_statement (assignment_expression left: (identifier) right: (decimal_integer_literal))) (expression_statement (method_invocation name: (identifier) arguments: (argument_list (identifier) (identifier) (identifier)))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list))) (expression_statement (assignment_expression left: (identifier) right: (decimal_integer_literal))) (expression_statement (method_invocation name: (identifier) arguments: (argument_list (identifier) (identifier) (identifier)))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list))))) |
static int getPairs ( int a [ ] ) {
int n = a . length ;
int count = ( n * ( n - 1 ) ) / 2 ;
return count ;
}
| static int getPairs ( int a [ ] ) { int n = a . length ; int count = ( n * ( n - 1 ) ) / 2 ; return count ; } | (method_declaration (modifiers) type: (integral_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (integral_type) name: (identifier) dimensions: (dimensions))) 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: (binary_expression left: (parenthesized_expression (binary_expression left: (identifier) right: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))))) right: (decimal_integer_literal)))) (return_statement (identifier)))) |
public static void main ( String [ ] args ) {
int a [ ] = {
2 , 4 , 3 , 1 };
System . out . println ( getPairs ( a ) ) ;
}
| public static void main ( String [ ] args ) { int a [ ] = { 2 , 4 , 3 , 1 } ; System . out . println ( getPairs ( a ) ) ; } | (method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (array_type element: (type_identifier) dimensions: (dimensions)) name: (identifier))) body: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) dimensions: (dimensions) value: (array_initializer (decimal_integer_literal) (decimal_integer_literal) (decimal_integer_literal) (decimal_integer_literal)))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (method_invocation name: (identifier) arguments: (argument_list (identifier)))))))) |
static int count ( int n ) {
return ( int ) ( 15 * Math . pow ( 16 , n - 1 ) ) ;
}
| static int count ( int n ) { return ( int ) ( 15 * Math . pow ( 16 , n - 1 ) ) ; } | (method_declaration (modifiers) type: (integral_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (integral_type) name: (identifier))) body: (block (return_statement (cast_expression type: (integral_type) value: (parenthesized_expression (binary_expression left: (decimal_integer_literal) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (decimal_integer_literal) (binary_expression left: (identifier) right: (decimal_integer_literal)))))))))) |
public static void main ( String args [ ] ) {
int n = 2 ;
System . out . println ( count ( n ) ) ;
}
| public static void main ( String args [ ] ) { int n = 2 ; System . out . println ( count ( n ) ) ; } | (method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (type_identifier) name: (identifier) dimensions: (dimensions))) body: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (method_invocation name: (identifier) arguments: (argument_list (identifier)))))))) |
static int countPairs ( int [ ] arr1 , int [ ] arr2 , int m , int n , int x ) {
int count = 0 ;
for ( int i = 0 ;
i < m ;
i ++ ) for ( int j = 0 ;
j < n ;
j ++ ) if ( ( arr1 [ i ] + arr2 [ j ] ) == x ) count ++ ;
return count ;
}
| static int countPairs ( int [ ] arr1 , int [ ] arr2 , int m , int n , int x ) { int count = 0 ; for ( int i = 0 ; i < m ; i ++ ) for ( int j = 0 ; j < n ; j ++ ) if ( ( arr1 [ i ] + arr2 [ j ] ) == x ) count ++ ; return count ; } | (method_declaration (modifiers) type: (integral_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (array_type element: (integral_type) dimensions: (dimensions)) name: (identifier)) (formal_parameter type: (array_type element: (integral_type) dimensions: (dimensions)) name: (identifier)) (formal_parameter type: (integral_type) name: (identifier)) (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))) (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: (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: (if_statement condition: (parenthesized_expression (binary_expression left: (parenthesized_expression (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (array_access array: (identifier) index: (identifier)))) right: (identifier))) consequence: (expression_statement (update_expression (identifier)))))) (return_statement (identifier)))) |
public static void main ( String [ ] args ) {
int arr1 [ ] = {
1 , 3 , 5 , 7 };
int arr2 [ ] = {
2 , 3 , 5 , 8 };
int m = arr1 . length ;
int n = arr2 . length ;
int x = 10 ;
System . out . println ( "Count = " + countPairs ( arr1 , arr2 , m , n , x ) ) ;
}
| public static void main ( String [ ] args ) { int arr1 [ ] = { 1 , 3 , 5 , 7 } ; int arr2 [ ] = { 2 , 3 , 5 , 8 } ; int m = arr1 . length ; int n = arr2 . length ; int x = 10 ; System . out . println ( " Count β = β " + countPairs ( arr1 , arr2 , m , n , x ) ) ; } | (method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (array_type element: (type_identifier) dimensions: (dimensions)) name: (identifier))) body: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) dimensions: (dimensions) value: (array_initializer (decimal_integer_literal) (decimal_integer_literal) (decimal_integer_literal) (decimal_integer_literal)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) dimensions: (dimensions) value: (array_initializer (decimal_integer_literal) (decimal_integer_literal) (decimal_integer_literal) (decimal_integer_literal)))) (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: (field_access object: (identifier) field: (identifier)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (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: (method_invocation name: (identifier) arguments: (argument_list (identifier) (identifier) (identifier) (identifier) (identifier))))))))) |
static int zzis ( int arr [ ] , int n ) {
int Z [ ] [ ] = new int [ n ] [ 2 ] ;
for ( int i = 0 ;
i < n ;
i ++ ) Z [ i ] [ 0 ] = Z [ i ] [ 1 ] = 1 ;
int res = 1 ;
for ( int i = 1 ;
i < n ;
i ++ ) {
for ( int j = 0 ;
j < i ;
j ++ ) {
if ( arr [ j ] < arr [ i ] && Z [ i ] [ 0 ] < Z [ j ] [ 1 ] + 1 ) Z [ i ] [ 0 ] = Z [ j ] [ 1 ] + 1 ;
if ( arr [ j ] > arr [ i ] && Z [ i ] [ 1 ] < Z [ j ] [ 0 ] + 1 ) Z [ i ] [ 1 ] = Z [ j ] [ 0 ] + 1 ;
}
if ( res < Math . max ( Z [ i ] [ 0 ] , Z [ i ] [ 1 ] ) ) res = Math . max ( Z [ i ] [ 0 ] , Z [ i ] [ 1 ] ) ;
}
return res ;
}
| static int zzis ( int arr [ ] , int n ) { int Z [ ] [ ] = new int [ n ] [ 2 ] ; for ( int i = 0 ; i < n ; i ++ ) Z [ i ] [ 0 ] = Z [ i ] [ 1 ] = 1 ; int res = 1 ; for ( int i = 1 ; i < n ; i ++ ) { for ( int j = 0 ; j < i ; j ++ ) { if ( arr [ j ] < arr [ i ] && Z [ i ] [ 0 ] < Z [ j ] [ 1 ] + 1 ) Z [ i ] [ 0 ] = Z [ j ] [ 1 ] + 1 ; if ( arr [ j ] > arr [ i ] && Z [ i ] [ 1 ] < Z [ j ] [ 0 ] + 1 ) Z [ i ] [ 1 ] = Z [ j ] [ 0 ] + 1 ; } if ( res < Math . max ( Z [ i ] [ 0 ] , Z [ i ] [ 1 ] ) ) res = Math . max ( Z [ i ] [ 0 ] , Z [ i ] [ 1 ] ) ; } return res ; } | (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))) body: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) dimensions: (dimensions) value: (array_creation_expression type: (integral_type) dimensions: (dimensions_expr (identifier)) dimensions: (dimensions_expr (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: (expression_statement (assignment_expression left: (array_access array: (array_access array: (identifier) index: (identifier)) index: (decimal_integer_literal)) right: (assignment_expression left: (array_access array: (array_access array: (identifier) index: (identifier)) index: (decimal_integer_literal)) right: (decimal_integer_literal))))) (local_variable_declaration type: (integral_type) 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 (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: (array_access array: (identifier) index: (identifier))) right: (binary_expression left: (array_access array: (array_access array: (identifier) index: (identifier)) index: (decimal_integer_literal)) right: (binary_expression left: (array_access array: (array_access array: (identifier) index: (identifier)) index: (decimal_integer_literal)) right: (decimal_integer_literal))))) consequence: (expression_statement (assignment_expression left: (array_access array: (array_access array: (identifier) index: (identifier)) index: (decimal_integer_literal)) right: (binary_expression left: (array_access array: (array_access array: (identifier) index: (identifier)) index: (decimal_integer_literal)) right: (decimal_integer_literal))))) (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (array_access array: (identifier) index: (identifier))) right: (binary_expression left: (array_access array: (array_access array: (identifier) index: (identifier)) index: (decimal_integer_literal)) right: (binary_expression left: (array_access array: (array_access array: (identifier) index: (identifier)) index: (decimal_integer_literal)) right: (decimal_integer_literal))))) consequence: (expression_statement (assignment_expression left: (array_access array: (array_access array: (identifier) index: (identifier)) index: (decimal_integer_literal)) right: (binary_expression left: (array_access array: (array_access array: (identifier) index: (identifier)) index: (decimal_integer_literal)) right: (decimal_integer_literal))))))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (array_access array: (array_access array: (identifier) index: (identifier)) index: (decimal_integer_literal)) (array_access array: (array_access array: (identifier) index: (identifier)) index: (decimal_integer_literal)))))) consequence: (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (array_access array: (array_access array: (identifier) index: (identifier)) index: (decimal_integer_literal)) (array_access array: (array_access array: (identifier) index: (identifier)) index: (decimal_integer_literal))))))))) (return_statement (identifier)))) |
public static void main ( String [ ] args ) {
int arr [ ] = {
10 , 22 , 9 , 33 , 49 , 50 , 31 , 60 };
int n = arr . length ;
System . out . println ( "Length of Longest " + "Zig-Zag subsequence is " + zzis ( arr , n ) ) ;
}
| public static void main ( String [ ] args ) { int arr [ ] = { 10 , 22 , 9 , 33 , 49 , 50 , 31 , 60 } ; int n = arr . length ; System . out . println ( " Length β of β Longest β " + " Zig - Zag β subsequence β is β " + zzis ( arr , n ) ) ; } | (method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (array_type element: (type_identifier) dimensions: (dimensions)) name: (identifier))) body: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) dimensions: (dimensions) value: (array_initializer (decimal_integer_literal) (decimal_integer_literal) (decimal_integer_literal) (decimal_integer_literal) (decimal_integer_literal) (decimal_integer_literal) (decimal_integer_literal) (decimal_integer_literal)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (field_access object: (identifier) field: (identifier)))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (binary_expression left: (binary_expression left: (string_literal) right: (string_literal)) right: (method_invocation name: (identifier) arguments: (argument_list (identifier) (identifier))))))))) |
static String constructPalin ( char [ ] str , int len ) {
int i = 0 , j = len - 1 ;
for ( ;
i < j ;
i ++ , j -- ) {
if ( str [ i ] == str [ j ] && str [ i ] != '*' ) continue ;
else if ( str [ i ] == str [ j ] && str [ i ] == '*' ) {
str [ i ] = 'a' ;
str [ j ] = 'a' ;
continue ;
}
else if ( str [ i ] == '*' ) {
str [ i ] = str [ j ] ;
continue ;
}
else if ( str [ j ] == '*' ) {
str [ j ] = str [ i ] ;
continue ;
}
System . out . println ( "Not Possible" ) ;
return "" ;
}
return String . valueOf ( str ) ;
}
| static String constructPalin ( char [ ] str , int len ) { int i = 0 , j = len - 1 ; for ( ; i < j ; i ++ , j -- ) { if ( str [ i ] == str [ j ] && str [ i ] != ' * ' ) continue ; else if ( str [ i ] == str [ j ] && str [ i ] == ' * ' ) { str [ i ] = ' a ' ; str [ j ] = ' a ' ; continue ; } else if ( str [ i ] == ' * ' ) { str [ i ] = str [ j ] ; continue ; } else if ( str [ j ] == ' * ' ) { str [ j ] = str [ i ] ; continue ; } System . out . println ( " Not β Possible " ) ; return " " ; } return String . valueOf ( str ) ; } | (method_declaration (modifiers) type: (type_identifier) name: (identifier) parameters: (formal_parameters (formal_parameter type: (array_type element: (integral_type) dimensions: (dimensions)) 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)) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (identifier) right: (decimal_integer_literal)))) (for_statement condition: (binary_expression left: (identifier) right: (identifier)) update: (update_expression (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: (array_access array: (identifier) index: (identifier))) right: (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (character_literal)))) consequence: (continue_statement) alternative: (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (array_access array: (identifier) index: (identifier))) right: (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (character_literal)))) consequence: (block (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (character_literal))) (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (character_literal))) (continue_statement)) alternative: (if_statement condition: (parenthesized_expression (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (character_literal))) consequence: (block (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (array_access array: (identifier) index: (identifier)))) (continue_statement)) alternative: (if_statement condition: (parenthesized_expression (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (character_literal))) consequence: (block (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (array_access array: (identifier) index: (identifier)))) (continue_statement)))))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (string_literal)))) (return_statement (string_literal)))) (return_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))))) |
public static void main ( String [ ] args ) {
String str = "bca*xc**b" ;
int len = str . length ( ) ;
System . out . println ( constructPalin ( str . toCharArray ( ) , len ) ) ;
}
| public static void main ( String [ ] args ) { String str = " bca * xc * * b " ; int len = str . length ( ) ; System . out . println ( constructPalin ( str . toCharArray ( ) , len ) ) ; } | (method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (array_type element: (type_identifier) dimensions: (dimensions)) name: (identifier))) body: (block (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (string_literal))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (method_invocation name: (identifier) arguments: (argument_list (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)) (identifier)))))))) |
static int countOperations ( int arr [ ] , int n ) {
int count = 0 ;
for ( int i = 0 ;
i < n - 1 ;
i ++ ) {
if ( arr [ i ] % 2 == 1 ) {
arr [ i ] ++ ;
arr [ i + 1 ] ++ ;
count += 2 ;
}
}
for ( int i = 0 ;
i < n ;
i ++ ) {
if ( arr [ i ] % 2 == 1 ) return - 1 ;
}
return count ;
}
| static int countOperations ( int arr [ ] , int n ) { int count = 0 ; for ( int i = 0 ; i < n - 1 ; i ++ ) { if ( arr [ i ] % 2 == 1 ) { arr [ i ] ++ ; arr [ i + 1 ] ++ ; count += 2 ; } } for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] % 2 == 1 ) return - 1 ; } return count ; } | (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))) body: (block (local_variable_declaration type: (integral_type) 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: (binary_expression left: (identifier) right: (decimal_integer_literal))) update: (update_expression (identifier)) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (decimal_integer_literal)) right: (decimal_integer_literal))) consequence: (block (expression_statement (update_expression (array_access array: (identifier) index: (identifier)))) (expression_statement (update_expression (array_access array: (identifier) index: (binary_expression left: (identifier) 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: (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (decimal_integer_literal)) right: (decimal_integer_literal))) consequence: (return_statement (unary_expression operand: (decimal_integer_literal)))))) (return_statement (identifier)))) |
public static void main ( String [ ] args ) {
int arr [ ] = {
2 , 3 , 4 , 5 , 6 };
int n = arr . length ;
System . out . print ( countOperations ( arr , n ) ) ;
}
| public static void main ( String [ ] args ) { int arr [ ] = { 2 , 3 , 4 , 5 , 6 } ; int n = arr . length ; System . out . print ( countOperations ( arr , n ) ) ; } | (method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (array_type element: (type_identifier) dimensions: (dimensions)) name: (identifier))) body: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) dimensions: (dimensions) value: (array_initializer (decimal_integer_literal) (decimal_integer_literal) (decimal_integer_literal) (decimal_integer_literal) (decimal_integer_literal)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (field_access object: (identifier) field: (identifier)))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (method_invocation name: (identifier) arguments: (argument_list (identifier) (identifier)))))))) |
public static void main ( String args [ ] ) {
Sum s = new Sum ( ) ;
int N = 8 , K = 3 ;
s . sumOfPrevK ( N , K ) ;
}
| public static void main ( String args [ ] ) { Sum s = new Sum ( ) ; int N = 8 , K = 3 ; s . sumOfPrevK ( N , K ) ; } | (method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (type_identifier) name: (identifier) dimensions: (dimensions))) body: (block (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (object_creation_expression type: (type_identifier) arguments: (argument_list)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal)) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (identifier)))))) |
static void find ( int n ) {
int b = n ;
int a = b * ( n - 1 ) ;
if ( a * b > n && a / b < n ) {
System . out . print ( "a = " + a + ", b = " + b ) ;
}
else System . out . println ( - 1 ) ;
}
| static void find ( int n ) { int b = n ; int a = b * ( n - 1 ) ; if ( a * b > n && a / b < n ) { System . out . print ( " a β = β " + a + " , β b β = β " + b ) ; } else System . out . println ( - 1 ) ; } | (method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (integral_type) name: (identifier))) body: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (identifier))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (identifier) right: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal)))))) (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (binary_expression left: (identifier) right: (identifier)) right: (identifier)) right: (binary_expression left: (binary_expression left: (identifier) right: (identifier)) right: (identifier)))) consequence: (block (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (binary_expression left: (binary_expression left: (binary_expression left: (string_literal) right: (identifier)) right: (string_literal)) right: (identifier)))))) alternative: (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (unary_expression operand: (decimal_integer_literal)))))))) |
public static void main ( String [ ] args ) {
int n = 10 ;
find ( n ) ;
}
| public static void main ( String [ ] args ) { int n = 10 ; find ( n ) ; } | (method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (array_type element: (type_identifier) dimensions: (dimensions)) name: (identifier))) body: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (expression_statement (method_invocation name: (identifier) arguments: (argument_list (identifier)))))) |
static double ReuleauxArea ( double r ) {
if ( r < 0 ) return - 1 ;
double A = 0.70477 * 2 * Math . pow ( r , 2 ) ;
return A ;
}
| static double ReuleauxArea ( double r ) { if ( r < 0 ) return - 1 ; double A = 0.70477 * 2 * Math . pow ( r , 2 ) ; return A ; } | (method_declaration (modifiers) type: (floating_point_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (floating_point_type) name: (identifier))) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) consequence: (return_statement (unary_expression operand: (decimal_integer_literal)))) (local_variable_declaration type: (floating_point_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (binary_expression left: (decimal_floating_point_literal) right: (decimal_integer_literal)) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (decimal_integer_literal)))))) (return_statement (identifier)))) |
public static void main ( String args [ ] ) {
double r = 6 ;
System . out . println ( ReuleauxArea ( r ) ) ;
}
| public static void main ( String args [ ] ) { double r = 6 ; System . out . println ( ReuleauxArea ( r ) ) ; } | (method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (type_identifier) name: (identifier) dimensions: (dimensions))) body: (block (local_variable_declaration type: (floating_point_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (method_invocation name: (identifier) arguments: (argument_list (identifier)))))))) |
static int getCount ( String a , String b ) {
if ( b . length ( ) % a . length ( ) != 0 ) return - 1 ;
int count = b . length ( ) / a . length ( ) ;
String str = "" ;
for ( int i = 0 ;
i < count ;
i ++ ) {
str = str + a ;
}
if ( str . equals ( b ) ) return count ;
return - 1 ;
}
| static int getCount ( String a , String b ) { if ( b . length ( ) % a . length ( ) != 0 ) return - 1 ; int count = b . length ( ) / a . length ( ) ; String str = " " ; for ( int i = 0 ; i < count ; i ++ ) { str = str + a ; } if ( str . equals ( b ) ) return count ; return - 1 ; } | (method_declaration (modifiers) type: (integral_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (type_identifier) name: (identifier)) (formal_parameter type: (type_identifier) name: (identifier))) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))) right: (decimal_integer_literal))) consequence: (return_statement (unary_expression operand: (decimal_integer_literal)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))))) (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (string_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 (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (identifier) right: (identifier)))))) (if_statement condition: (parenthesized_expression (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))) consequence: (return_statement (identifier))) (return_statement (unary_expression operand: (decimal_integer_literal))))) |
public static void main ( String [ ] args ) {
String a = "geeks" ;
String b = "geeksgeeks" ;
System . out . println ( getCount ( a , b ) ) ;
}
| public static void main ( String [ ] args ) { String a = " geeks " ; String b = " geeksgeeks " ; System . out . println ( getCount ( a , b ) ) ; } | (method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (array_type element: (type_identifier) dimensions: (dimensions)) name: (identifier))) body: (block (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (string_literal))) (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (string_literal))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (method_invocation name: (identifier) arguments: (argument_list (identifier) (identifier)))))))) |
public static void main ( String [ ] args ) {
int N = 3 ;
GFG a = new GFG ( ) ;
System . out . println ( a . nthTerm ( N ) ) ;
}
| public static void main ( String [ ] args ) { int N = 3 ; GFG a = new GFG ( ) ; System . out . println ( a . nthTerm ( N ) ) ; } | (method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (array_type element: (type_identifier) dimensions: (dimensions)) name: (identifier))) body: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (object_creation_expression type: (type_identifier) arguments: (argument_list)))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))))))) |
public static int nthTerm ( int N ) {
return N * N + ( N + 1 ) * ( N + 1 ) ;
}
| public static int nthTerm ( int N ) { return N * N + ( N + 1 ) * ( N + 1 ) ; } | (method_declaration (modifiers) type: (integral_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (integral_type) name: (identifier))) body: (block (return_statement (binary_expression left: (binary_expression left: (identifier) right: (identifier)) right: (binary_expression left: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) right: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal)))))))) |
public static void main ( String [ ] args ) {
int N = 3 ;
System . out . println ( nthTerm ( N ) ) ;
}
| public static void main ( String [ ] args ) { int N = 3 ; System . out . println ( nthTerm ( N ) ) ; } | (method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (array_type element: (type_identifier) dimensions: (dimensions)) name: (identifier))) body: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (method_invocation name: (identifier) arguments: (argument_list (identifier)))))))) |
static long gcd ( long a , long b ) {
if ( a == 0 ) return b ;
return gcd ( b % a , a ) ;
}
| static long gcd ( long a , long b ) { if ( a == 0 ) return b ; return gcd ( b % a , a ) ; } | (method_declaration (modifiers) type: (integral_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (integral_type) name: (identifier)) (formal_parameter type: (integral_type) name: (identifier))) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) consequence: (return_statement (identifier))) (return_statement (method_invocation name: (identifier) arguments: (argument_list (binary_expression left: (identifier) right: (identifier)) (identifier)))))) |
static long powGCD ( long a , long n , long b ) {
for ( int i = 0 ;
i < n ;
i ++ ) a = a * a ;
return gcd ( a , b ) ;
}
| static long powGCD ( long a , long n , long b ) { for ( int i = 0 ; i < n ; i ++ ) a = a * a ; return gcd ( a , b ) ; } | (method_declaration (modifiers) type: (integral_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (integral_type) name: (identifier)) (formal_parameter type: (integral_type) name: (identifier)) (formal_parameter type: (integral_type) name: (identifier))) body: (block (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: (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (identifier) right: (identifier))))) (return_statement (method_invocation name: (identifier) arguments: (argument_list (identifier) (identifier)))))) |
public static void main ( String [ ] args ) {
long a = 10 , b = 5 , n = 2 ;
System . out . println ( powGCD ( a , n , b ) ) ;
}
| public static void main ( String [ ] args ) { long a = 10 , b = 5 , n = 2 ; System . out . println ( powGCD ( a , n , b ) ) ; } | (method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (array_type element: (type_identifier) dimensions: (dimensions)) 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)) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (method_invocation name: (identifier) arguments: (argument_list (identifier) (identifier) (identifier)))))))) |
static Boolean divisibleBy20 ( String num ) {
int lastTwoDigits = Integer . parseInt ( num . substring ( num . length ( ) - 2 , num . length ( ) ) ) ;
return ( ( lastTwoDigits % 5 == 0 ) && ( lastTwoDigits % 4 == 0 ) ) ;
}
| static Boolean divisibleBy20 ( String num ) { int lastTwoDigits = Integer . parseInt ( num . substring ( num . length ( ) - 2 , num . length ( ) ) ) ; return ( ( lastTwoDigits % 5 == 0 ) && ( lastTwoDigits % 4 == 0 ) ) ; } | (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 (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)) right: (decimal_integer_literal)) (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))))))) (return_statement (parenthesized_expression (binary_expression left: (parenthesized_expression (binary_expression left: (binary_expression left: (identifier) right: (decimal_integer_literal)) right: (decimal_integer_literal))) right: (parenthesized_expression (binary_expression left: (binary_expression left: (identifier) right: (decimal_integer_literal)) right: (decimal_integer_literal)))))))) |
public static void main ( String [ ] args ) {
String num = "63284689320" ;
if ( divisibleBy20 ( num ) == true ) System . out . println ( "Yes" ) ;
else System . out . println ( "No" ) ;
}
| public static void main ( String [ ] args ) { String num = "63284689320" ; if ( divisibleBy20 ( num ) == true ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } | (method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (array_type element: (type_identifier) dimensions: (dimensions)) name: (identifier))) body: (block (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (string_literal))) (if_statement condition: (parenthesized_expression (binary_expression left: (method_invocation name: (identifier) arguments: (argument_list (identifier))) right: (true))) 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 (string_literal))))))) |
static int findNumOfPair ( int a [ ] , int n ) {
Arrays . sort ( a ) ;
int ans = 0 ;
for ( int i = 0 ;
i < n ;
++ i ) {
if ( a [ i ] <= 0 ) continue ;
int len = a . length ;
int j = 0 ;
while ( j < len ) {
if ( a [ j ] == n ) {
return j ;
}
else {
j = j + 1 ;
}
}
ans += i - j ;
}
return ans ;
}
| static int findNumOfPair ( int a [ ] , int n ) { Arrays . sort ( a ) ; int ans = 0 ; for ( int i = 0 ; i < n ; ++ i ) { if ( a [ i ] <= 0 ) continue ; int len = a . length ; int j = 0 ; while ( j < len ) { if ( a [ j ] == n ) { return j ; } else { j = j + 1 ; } } ans += i - j ; } return ans ; } | (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))) body: (block (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))) (local_variable_declaration type: (integral_type) 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: (continue_statement)) (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: (decimal_integer_literal))) (while_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (identifier))) consequence: (block (return_statement (identifier))) alternative: (block (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (identifier) right: (decimal_integer_literal)))))))) (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (identifier) right: (identifier)))))) (return_statement (identifier)))) |
public static void main ( String [ ] args ) {
int a [ ] = {
3 , - 2 , 1 };
int n = a . length ;
int ans = findNumOfPair ( a , n ) ;
System . out . println ( ans ) ;
}
| public static void main ( String [ ] args ) { int a [ ] = { 3 , - 2 , 1 } ; int n = a . length ; int ans = findNumOfPair ( a , n ) ; System . out . println ( ans ) ; } | (method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (array_type element: (type_identifier) dimensions: (dimensions)) name: (identifier))) body: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) dimensions: (dimensions) value: (array_initializer (decimal_integer_literal) (unary_expression operand: (decimal_integer_literal)) (decimal_integer_literal)))) (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: (method_invocation name: (identifier) arguments: (argument_list (identifier) (identifier))))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (identifier)))))) |
public static double area_cicumscribed ( double a ) {
return ( a * a * ( PI / 3 ) ) ;
}
| public static double area_cicumscribed ( double a ) { return ( a * a * ( PI / 3 ) ) ; } | (method_declaration (modifiers) type: (floating_point_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (floating_point_type) name: (identifier))) body: (block (return_statement (parenthesized_expression (binary_expression left: (binary_expression left: (identifier) right: (identifier)) right: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal)))))))) |
public static void main ( String [ ] args ) {
double a = 6.0 ;
System . out . println ( "Area of circumscribed circle is :" + area_cicumscribed ( a ) ) ;
}
| public static void main ( String [ ] args ) { double a = 6.0 ; System . out . println ( " Area β of β circumscribed β circle β is β : " + area_cicumscribed ( a ) ) ; } | (method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (array_type element: (type_identifier) dimensions: (dimensions)) name: (identifier))) body: (block (local_variable_declaration type: (floating_point_type) declarator: (variable_declarator name: (identifier) value: (decimal_floating_point_literal))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (binary_expression left: (string_literal) right: (method_invocation name: (identifier) arguments: (argument_list (identifier))))))))) |