dhyuti-n/xlcost-variable-roles huggingface dataset:
Java program:
import java . util . * ; class GFG { static void checkstateA ( String n ) { if ( n . charAt ( 0 ) == '0' ) stateB ( n . substring ( 1 ) ) ; else stateD ( n . substring ( 1 ) ) ; } static void stateB ( String n ) { if ( n . length ( ) == 0 ) System . out . println ( " string ▁ not ▁ accepted " ) ; else { if ( n . charAt ( 0 ) == '1' ) stateC ( n . substring ( 1 ) ) ; else stateD ( n . substring ( 1 ) ) ; } } static void stateC ( String n ) { System . out . println ( " String ▁ accepted " ) ; } static void stateD ( String n ) { if ( n . length ( ) == 0 ) System . out . println ( " string ▁ not ▁ accepted " ) ; else { if ( n . charAt ( 0 ) == '1' ) stateD ( n . substring ( 1 ) ) ; else stateE ( n . substring ( 1 ) ) ; } } static void stateE ( String n ) { if ( n . length ( ) == 0 ) System . out . println ( " string ▁ not ▁ accepted " ) ; else { if ( n . charAt ( 0 ) == '0' ) stateE ( n . substring ( 1 ) ) ; else stateF ( n . substring ( 1 ) ) ; } } static void stateF ( String n ) { if ( n . length ( ) == 0 ) System . out . println ( " string ▁ accepred " ) ; else { if ( n . charAt ( 0 ) == '1' ) stateD ( n . substring ( 1 ) ) ; else stateE ( n . substring ( 1 ) ) ; } } public static void main ( String args [ ] ) { String n = "0100101" ; checkstateA ( n ) ; } }

Class/struct names: GFG
Java program:
import java . util . * ; class GFG { public static int HogbenNumber ( int a ) { int p = ( int ) ( Math . pow ( a , 2 ) - a + 1 ) ; return p ; } public static void main ( String args [ ] ) { int N = 10 ; System . out . print ( HogbenNumber ( N ) ) ; } }

Class/struct names: GFG
Java program:
class GFG { public static void check_string_exist ( String S ) { int size = S . length ( ) ; boolean check = true ; for ( int i = 0 ; i < size ; i ++ ) { if ( S . charAt ( i ) != S . charAt ( ( i + 2 ) % size ) ) { check = false ; break ; } } if ( check ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } public static void main ( String [ ] args ) { String S = " papa " ; check_string_exist ( S ) ; } }

Accumulator variables: i
Iterator variables: i
Boolean variables: check
Class/struct names: GFG
Java program:
class GFG { static int getProduct ( int n ) { int product = 1 ; while ( n != 0 ) { product = product * ( n % 10 ) ; n = n / 10 ; } return product ; } static int productinRange ( int l , int r ) { if ( r - l > 9 ) return 0 ; else { int p = 1 ; for ( int i = l ; i <= r ; i ++ ) p *= getProduct ( i ) ; return p ; } } public static void main ( String [ ] args ) { int l = 11 , r = 15 ; System . out . print ( productinRange ( l , r ) + "NEW_LINE"); l = 1 ; r = 15 ; System . out . print ( productinRange ( l , r ) ) ; } }

Accumulator variables: i, p
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int checkQwertyRow ( char x ) { Character [ ] first_row1 = { '1' , '2' , '3' , '4' , '5' , '6' , '7' , '8' , '9' , '0' , ' - ' , ' = ' } ; Set < Character > first_row = new HashSet < > ( Arrays . asList ( first_row1 ) ) ; Character [ ] second_row1 = { ' Q ' , ' W ' , ' E ' , ' R ' , ' T ' , ' Y ' , ' U ' , ' I ' , ' O ' , ' P ' , ' [ ' , ' ] ' , ' q ' , ' w ' , ' e ' , ' r ' , ' t ' , ' y ' , ' u ' , ' i ' , ' o ' , ' p ' } ; Set < Character > second_row = new HashSet < > ( Arrays . asList ( second_row1 ) ) ; Character [ ] third_row1 = { ' A ' , ' S ' , ' D ' , ' F ' , ' G ' , ' H ' , ' J ' , ' K ' , ' L ' , ' ; ' , ' : ' , ' a ' , ' s ' , ' d ' , ' f ' , ' g ' , ' h ' , ' j ' , ' k ' , ' l ' } ; Set < Character > third_row = new HashSet < > ( Arrays . asList ( third_row1 ) ) ; Character [ ] fourth_row1 = { ' Z ' , ' X ' , ' C ' , ' V ' , ' B ' , ' N ' , ' M ' , ' , ' , ' . ' , ' / ' , ' z ' , ' x ' , ' c ' , ' v ' , ' b ' , ' n ' , ' m ' } ; Set < Character > fourth_row = new HashSet < > ( Arrays . asList ( fourth_row1 ) ) ; if ( first_row . contains ( x ) ) { return 1 ; } else if ( second_row . contains ( x ) ) { return 2 ; } else if ( third_row . contains ( x ) ) { return 3 ; } else if ( fourth_row . contains ( x ) ) { return 4 ; } return 0 ; } static boolean checkValidity ( String str ) { char x = str . charAt ( 0 ) ; int row = checkQwertyRow ( x ) ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) { x = str . charAt ( i ) ; if ( row != checkQwertyRow ( x ) ) { return false ; } } return true ; } public static void main ( String [ ] args ) { String str = " GeeksforGeeks " ; if ( checkValidity ( str ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }

Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int fib ( long n ) { int f0 = 0 ; int f1 = 1 ; if ( n == 0 ) return 0 ; if ( n == 1 ) return 1 ; else { int rem = ( int ) ( n % 60 ) ; if ( rem == 0 ) return 0 ; for ( int i = 2 ; i < rem + 3 ; i ++ ) { int f = ( f0 + f1 ) % 60 ; f0 = f1 ; f1 = f ; } int s = f1 - 1 ; return s ; } } public static void main ( String args [ ] ) { int m = 10087887 ; long n = 2983097899L ; int Final = ( int ) Math . abs ( fib ( n ) - fib ( m - 1 ) ) ; System . out . println ( Final % 10 ) ; } }

Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static void printSinX ( int N ) { int Xi = 0 ; int num = 1 ; while ( N -- > 0 ) { System . out . print ( " X " + num + " ▁ = ▁ " + Xi ) ; System . out . print ( " ▁ sin ( X " + num + " ) ▁ = ▁ " ) ; System . out . printf ( " % .6f " , Math . sin ( Xi ) ) ; System . out . println ( ) ; num += 1 ; Xi += 710 ; } } public static void main ( String [ ] args ) { int N = 5 ; printSinX ( N ) ; } }

Accumulator variables: N, Xi, num
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static void sumBetweenZero ( int arr [ ] , int N ) { int i = 0 ; Vector < Integer > A = new Vector < Integer > ( ) ; int sum = 0 ; for ( i = 0 ; i < N ; i ++ ) { if ( arr [ i ] == 0 ) { i ++ ; break ; } } for ( ; i < N ; i ++ ) { if ( arr [ i ] == 0 ) { A . add ( sum ) ; sum = 0 ; } else { sum += arr [ i ] ; } } for ( int j = 0 ; j < A . size ( ) ; j ++ ) { System . out . print ( A . get ( j ) + " ▁ " ) ; } if ( A . size ( ) == 0 ) System . out . print ( " - 1" ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 0 , 3 , 4 , 0 , 4 , 4 , 0 , 2 , 1 , 4 , 0 , 3 } ; int N = arr . length ; sumBetweenZero ( arr , N ) ; } }

Index/key variables: i
Accumulator variables: i, j, sum
Iterator variables: i, j
Class/struct names: GFG
Java program:
class GFG { static int nthTerm ( int N ) { if ( N == 1 ) { return 2 ; } return ( ( N - 1 ) * 13 ) + nthTerm ( N - 1 ) ; } public static void main ( String [ ] args ) { int N = 17 ; System . out . print ( nthTerm ( N ) + "NEW_LINE"); } }

Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static void maximumSubsequence ( int arr [ ] , int N ) { HashMap < Integer , Integer > M = new HashMap < Integer , Integer > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { if ( M . containsKey ( arr [ i ] ) ) { M . put ( arr [ i ] , M . get ( arr [ i ] ) + 1 ) ; } else { M . put ( arr [ i ] , 1 ) ; } } int distinct_size = M . size ( ) ; int maxFreq = 1 ; for ( Map . Entry < Integer , Integer > it : M . entrySet ( ) ) { maxFreq = Math . max ( maxFreq , it . getValue ( ) ) ; } System . out . print ( Math . max ( Math . min ( distinct_size , maxFreq - 1 ) , Math . min ( distinct_size - 1 , maxFreq ) ) ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 2 , 3 , 4 , 4 , 4 , 4 , 4 , 5 } ; int N = arr . length ; maximumSubsequence ( arr , N ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int countCharacters ( List < String > strings , String chars ) { int res = 0 ; Map < Character , Integer > freq = new HashMap < > ( ) ; for ( int i = 0 ; i < chars . length ( ) ; i ++ ) { freq . put ( chars . charAt ( i ) , freq . getOrDefault ( chars . charAt ( i ) , 0 ) + 1 ) ; } for ( String st : strings ) { boolean flag = true ; for ( char c : st . toCharArray ( ) ) { if ( ! freq . containsKey ( c ) ) { flag = false ; break ; } } if ( flag ) res += st . length ( ) ; } return res ; } public static void main ( String [ ] args ) { List < String > strings = Arrays . asList ( " hi " , " data " , " geeksforgeeks " ) ; String chars = " tiadhae " ; System . out . println ( countCharacters ( strings , chars ) ) ; } }

Accumulator variables: i, res
Iterator variables: c, i, st
Boolean variables: flag
Class/struct names: GFG
Java program:
class GFG { static void arrayConstruct ( int N ) { for ( int i = 2 ; i <= N ; i = i + 2 ) System . out . print ( i + " ▁ " ) ; for ( int i = 1 ; i < N - 1 ; i = i + 2 ) System . out . print ( i + " ▁ " ) ; System . out . print ( N - 1 + ( N / 2 ) + "NEW_LINE"); } static void createArray ( int N ) { if ( N % 4 == 0 ) arrayConstruct ( N ) ; else System . out . print ( - 1 + "NEW_LINE"); } public static void main ( String [ ] args ) { int N = 8 ; createArray ( N ) ; } }

Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; import java . util . * ; class GFG { static int distinctSubstring ( String P , String Q , int K , int N ) { Set < String > S = new HashSet < > ( ) ; for ( int i = 0 ; i < N ; ++ i ) { int sum = 0 ; String s = " " ; for ( int j = i ; j < N ; ++ j ) { int pos = P . charAt ( j ) - ' a ' ; sum += Q . charAt ( pos ) - '0' ; s += P . charAt ( j ) ; if ( sum <= K ) { S . add ( s ) ; } else { break ; } } } return S . size ( ) ; } public static void main ( String args [ ] ) { String S = " abcde " ; String W = "12345678912345678912345678" ; int K = 5 ; int N = S . length ( ) ; System . out . println ( distinctSubstring ( S , W , K , N ) ) ; } }

Accumulator variables: s, sum
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . regex . Pattern ; import java . util . regex . Matcher ; class GFG { static int countCharacters ( String password ) { int count = 0 ; Pattern digit = Pattern . compile ( " ( \\ d ) " ) ; Pattern upper = Pattern . compile ( " ( [ A - Z ] ) " ) ; Pattern lower = Pattern . compile ( " ( [ a - z ] ) " ) ; Pattern spChar = Pattern . compile ( " ( \\ W ) " ) ; Matcher Digit = digit . matcher ( password ) ; Matcher Upper = upper . matcher ( password ) ; Matcher Lower = lower . matcher ( password ) ; Matcher Special = spChar . matcher ( password ) ; if ( ! Digit . find ( ) ) { count ++ ; } if ( ! Upper . find ( ) ) { count ++ ; } if ( ! Lower . find ( ) ) { count ++ ; } if ( ! Special . find ( ) ) { count ++ ; } if ( ( count + password . length ( ) ) < 8 ) { count = count + 8 - ( count + password . length ( ) ) ; } return count ; } public static void main ( String args [ ] ) { String password1 = " Geeksforgeeks " ; System . out . println ( countCharacters ( password1 ) ) ; String password2 = " Geeks1" ; System . out . println ( countCharacters ( password2 ) ) ; } }

Accumulator variables: count
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int distinctSubString ( String P , String Q , int K , int N ) { HashSet < String > S = new HashSet < String > ( ) ; for ( int i = 0 ; i < N ; ++ i ) { int sum = 0 ; String s = " " ; for ( int j = i ; j < N ; ++ j ) { int pos = P . charAt ( j ) - ' a ' ; sum += Q . charAt ( pos ) - '0' ; s += P . charAt ( j ) ; if ( sum <= K ) { S . add ( s ) ; } else { break ; } } } return S . size ( ) ; } public static void main ( String [ ] args ) { String P = " abcde " ; String Q = "12345678912345678912345678" ; int K = 5 ; int N = P . length ( ) ; System . out . print ( distinctSubString ( P , Q , K , N ) ) ; } }

Accumulator variables: s, sum
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static void printPattern ( int n ) { int i , j ; for ( i = 1 ; i <= n ; i ++ ) { for ( j = 1 ; j < 2 * n ; j ++ ) { if ( j == ( n - i + 1 ) || j == ( n + i - 1 ) ) { System . out . print ( " * ▁ " ) ; } else if ( ( i >= 4 && i <= n - 4 ) && ( j == n - i + 4 j == n + i - 4 ) ) { System . out . print ( " * ▁ " ) ; } else if ( i == n || ( i == n - 4 && j >= n - ( n - 2 * 4 ) && j <= n + n - 2 * 4 ) ) { System . out . print ( " * ▁ " ) ; } else { System . out . print ( " ▁ " + " ▁ " ) ; } } System . out . print ( "NEW_LINE"); } } public static void main ( String [ ] args ) { int N = 9 ; printPattern ( N ) ; } }

Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
class GFG { static boolean isKAlternating ( String s , int k ) { if ( s . length ( ) < k ) return false ; int checker = 0 ; for ( int i = 0 ; i < k ; i ++ ) { int bitAtIndex = s . charAt ( i ) - ' a ' ; if ( ( checker & ( 1 << bitAtIndex ) ) > 0 ) { return false ; } checker = checker | ( 1 << bitAtIndex ) ; } for ( int i = k ; i < s . length ( ) ; i ++ ) if ( s . charAt ( i - k ) != s . charAt ( i ) ) return false ; return true ; } public static void main ( String [ ] args ) { String str = " acdeac " ; int K = 4 ; if ( isKAlternating ( str , K ) ) System . out . print ( " Yes " + "NEW_LINE"); else System . out . print ( " No " + "NEW_LINE"); } }

Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int MAX = 100000 ; static void findFactors ( int N ) { int temp = ( int ) Math . sqrt ( N ) ; int [ ] factor = new int [ MAX ] ; Arrays . fill ( factor , 1 ) ; int i , j , k ; int len1 = 1 ; while ( temp % 2 == 0 ) { factor [ len1 ++ ] = 2 ; factor [ len1 ++ ] = 2 ; temp /= 2 ; } for ( j = 3 ; j < Math . sqrt ( temp ) ; j += 2 ) { while ( temp % j == 0 ) { factor [ len1 ++ ] = j ; factor [ len1 ++ ] = j ; temp /= j ; } } if ( temp > 2 ) { factor [ len1 ++ ] = temp ; factor [ len1 ++ ] = temp ; } int [ ] [ ] M = new int [ len1 ] [ MAX ] ; int tpc = 0 , tpr = 0 ; M [ 0 ] [ 0 ] = 1 ; j = 1 ; while ( j < len1 ) { if ( factor [ j ] != factor [ j - 1 ] ) { tpr ++ ; M [ tpr ] [ 0 ] = factor [ j ] ; j ++ ; tpc = 1 ; } else { M [ tpr ] [ tpc ] = M [ tpr ] [ tpc - 1 ] * factor [ j ] ; j ++ ; tpc ++ ; } } int [ ] arr1 = new int [ MAX ] ; int [ ] arr2 = new int [ MAX ] ; int l1 , l2 ; l1 = l2 = 1 ; arr1 [ 0 ] = arr2 [ 0 ] = 1 ; for ( i = 1 ; i < tpr + 1 ; i ++ ) { for ( j = 0 ; M [ i ] [ j ] != 0 ; j ++ ) { for ( k = 0 ; k < l1 ; k ++ ) { arr2 [ l2 ++ ] = arr1 [ k ] * M [ i ] [ j ] ; } } for ( j = l1 ; j < l2 ; j ++ ) { arr1 [ j ] = arr2 [ j ] ; } l1 = l2 ; } for ( i = 0 ; i < l2 ; i ++ ) { System . out . print ( arr2 [ i ] + " ▁ " ) ; } } public static void main ( String [ ] args ) { int N = 900 ; findFactors ( N ) ; } }

Index/key variables: MAX, i, j, k, len1, tpc, tpr
Accumulator variables: i, j, k, l2, len1, temp, tpc, tpr
Iterator variables: i, j, k
Class/struct names: GFG
Java program:
class GFG { static int matrix [ ] [ ] = new int [ 100 ] [ 100 ] ; static void printRequiredMatrix ( int n ) { if ( n == 1 ) { System . out . println ( "1" ) ; } else if ( n % 2 != 0 ) { System . out . println ( " - 1" ) ; } else { for ( int i = 0 ; i < n ; i ++ ) { matrix [ i ] [ i ] = n ; } int u = n - 1 ; for ( int i = 0 ; i < n - 1 ; i ++ ) { matrix [ i ] [ u ] = i + 1 ; for ( int j = 1 ; j < n / 2 ; j ++ ) { int a = ( i + j ) % ( n - 1 ) ; int b = ( i - j + n - 1 ) % ( n - 1 ) ; if ( a < b ) { int temp = a ; a = b ; b = temp ; } matrix [ b ] [ a ] = i + 1 ; } } for ( int i = 0 ; i < n ; i ++ ) for ( int j = 0 ; j < i ; j ++ ) matrix [ i ] [ j ] = matrix [ j ] [ i ] + n ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) System . out . print ( matrix [ i ] [ j ] + " ▁ " ) ; System . out . println ( ) ; } } System . out . println ( ) ; } public static void main ( String [ ] args ) { int n = 1 ; printRequiredMatrix ( n ) ; n = 3 ; printRequiredMatrix ( n ) ; n = 6 ; printRequiredMatrix ( n ) ; } }

Index/key variables: a, b, i, j, u
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
class GFG { static int countSubstring ( String S , int n ) { int ans = 0 ; int i = 0 ; while ( i < n ) { int cnt0 = 0 , cnt1 = 0 ; if ( S . charAt ( i ) == '0' ) { while ( i < n && S . charAt ( i ) == '0' ) { cnt0 ++ ; i ++ ; } int j = i ; while ( j < n && S . charAt ( j ) == '1' ) { cnt1 ++ ; j ++ ; } } else { while ( i < n && S . charAt ( i ) == '1' ) { cnt1 ++ ; i ++ ; } int j = i ; while ( j < n && S . charAt ( j ) == '0' ) { cnt0 ++ ; j ++ ; } } ans += Math . min ( cnt0 , cnt1 ) ; } return ans ; } static public void main ( String args [ ] ) { String S = "0001110010" ; int n = S . length ( ) ; System . out . println ( countSubstring ( S , n ) ) ; } }

Accumulator variables: ans, cnt0, cnt1, i, j
Class/struct names: GFG
Java program:
class GFG { static void findNumbers ( int n ) { int i = 1 ; while ( i <= n ) { System . out . print ( ( 3 * i * ( i - 1 ) + 1 ) + " ▁ " ) ; i ++ ; } } public static void main ( String [ ] args ) { int n = 4 ; findNumbers ( n ) ; } }

Accumulator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; import java . lang . * ; import java . io . * ; class GFG { static void decToOctal ( int n ) { int octalNum [ ] = new int [ 100 ] ; int i = 0 ; while ( n != 0 ) { octalNum [ i ] = n % 8 ; n = n / 8 ; i ++ ; } for ( int j = i - 1 ; j >= 0 ; j -- ) System . out . print ( octalNum [ j ] ) ; System . out . println ( "NEW_LINE"); } static void nDigitPerfectSquares ( int n ) { int decimal = ( int ) Math . pow ( Math . ceil ( Math . sqrt ( Math . pow ( 8 , n ) ) ) - 1 , 2 ) ; decToOctal ( decimal ) ; } public static void main ( String [ ] args ) { int n = 2 ; nDigitPerfectSquares ( n ) ; } }

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: j
Class/struct names: GFG
Java program:
class GFG { static String s ; static void reverseStr ( int l , int h ) { int n = h - l ; for ( int i = 0 ; i < n / 2 ; i ++ ) { s = swap ( i + l , n - i - 1 + l ) ; } } static void reverseString ( int A [ ] , int n ) { reverseStr ( 0 , A [ 0 ] ) ; for ( int i = 1 ; i < n ; i ++ ) reverseStr ( A [ i - 1 ] , A [ i ] ) ; reverseStr ( A [ n - 1 ] , s . length ( ) ) ; } static String swap ( int i , int j ) { char ch [ ] = s . toCharArray ( ) ; char temp = ch [ i ] ; ch [ i ] = ch [ j ] ; ch [ j ] = temp ; return String . valueOf ( ch ) ; } public static void main ( String [ ] args ) { s = " abcdefgh " ; int A [ ] = { 2 , 4 , 6 } ; int n = A . length ; reverseString ( A , n ) ; System . out . print ( s ) ; } }

Index/key variables: i, j
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static boolean Formatted ( String s ) { Vector < Character > k = new Vector < Character > ( ) ; int i = 0 ; while ( i < s . length ( ) ) { if ( s . charAt ( i ) == ' ) ' || s . charAt ( i ) == ' ( ' ) { k . add ( s . charAt ( i ) ) ; i += 1 ; } else { char st = 0 ; while ( s . charAt ( i ) != ' ) ' && s . charAt ( i ) != ' ) ' ) { st = s . charAt ( i ) ; i = i + 1 ; } k . add ( st ) ; } } int depth = 0 , flag = 1 ; int open = 0 , close = 0 ; for ( char i2 : k ) { if ( i2 == ' ( ' ) { depth += 1 ; open += 1 ; } else if ( i2 == ' ) ' ) { depth -= 1 ; close += 1 ; } else { if ( i2 - '0' != depth ) { flag = 0 ; break ; } } } if ( open != close ) flag = 0 ; return ( flag == 1 ) ? true : false ; } public static void main ( String [ ] args ) { String s = " ( (2 ) ( (3 ) ) ) " ; boolean k = Formatted ( s ) ; if ( k == true ) System . out . printf ( " Yes " ) ; else System . out . printf ( " No " ) ; } }

Accumulator variables: close, depth, i, open
Iterator variables: i2
Class/struct names: GFG
Java program:
class GFG { static int findSum ( int [ ] arr , int n , int k ) { if ( k <= n - 2 ) return ( arr [ n - 1 ] - arr [ 0 ] ) ; return 0 ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 2 , 3 , 4 } ; int n = arr . length ; int k = 1 ; System . out . println ( findSum ( arr , n , k ) ) ; } }

Class/struct names: GFG
Java program:
class GFG { static int maxSubStr ( String str , int n ) { int count0 = 0 , count1 = 0 ; int cnt = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( str . charAt ( i ) == '0' ) { count0 ++ ; } else { count1 ++ ; } if ( count0 == count1 ) { cnt ++ ; } } if ( cnt == 0 ) { return - 1 ; } return cnt ; } public static void main ( String [ ] args ) { String str = "0100110101" ; int n = str . length ( ) ; System . out . println ( maxSubStr ( str , n ) ) ; } }

Accumulator variables: cnt, count0, count1, i
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static long squareDigitSum ( String s ) { long lengthN = s . length ( ) ; long result = ( lengthN / 9 ) * 81 + ( long ) Math . pow ( ( lengthN % 9 ) , 2 ) ; return result ; } public static void main ( String [ ] args ) { String s = "1111" ; System . out . println ( squareDigitSum ( s ) ) ; } }

Class/struct names: GFG
Java program:
class temp { static String getString ( char x ) { String s = String . valueOf ( x ) ; return s ; } static boolean solve ( String s1 , String s2 ) { String a = getString ( s1 . charAt ( 0 ) ) , b = getString ( s2 . charAt ( 0 ) ) ; for ( int i = 1 ; i < s1 . length ( ) ; i ++ ) if ( s1 . charAt ( i ) != s1 . charAt ( i - 1 ) ) { a += getString ( s1 . charAt ( i ) ) ; } for ( int i = 1 ; i < s2 . length ( ) ; i ++ ) if ( s2 . charAt ( i ) != s2 . charAt ( i - 1 ) ) { b += getString ( s2 . charAt ( i ) ) ; } if ( a . equals ( b ) ) return true ; return false ; } public static void main ( String [ ] args ) { String s1 = " Geeks " , s2 = " Geks " ; if ( solve ( s1 , s2 ) ) System . out . print ( " Yes " ) ; else System . out . print ( " No " ) ; } }

Accumulator variables: a, b, i
Iterator variables: i
Class/struct names: temp
Java program:
import java . util . * ; class GFG { static int x = 26 ; static int mod = 3001 ; static void CntSubstr ( char [ ] s , int l ) { int hash = 0 ; for ( int i = 0 ; i < l ; i ++ ) { hash = ( hash * x + ( s [ i ] - 97 ) ) % mod ; } int pow_l = 1 ; for ( int i = 0 ; i < l - 1 ; i ++ ) { pow_l = ( pow_l * x ) % mod ; } HashSet < Integer > result = new HashSet < Integer > ( ) ; result . add ( hash ) ; for ( int i = l ; i < s . length ; i ++ ) { hash = ( ( hash - pow_l * ( s [ i - l ] - 97 ) + 2 * mod ) * x + ( s [ i ] - 97 ) ) % mod ; result . add ( hash ) ; } System . out . println ( result . size ( ) ) ; } public static void main ( String [ ] args ) { String s = " abcba " ; int l = 2 ; CntSubstr ( s . toCharArray ( ) , l ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { private static boolean isValidString ( String str , int n ) { int index = str . indexOf ( " b " ) ; if ( index == 0 ) return false ; while ( index != - 1 ) { if ( str . charAt ( index - 1 ) != ' a ' ) return false ; if ( index + 1 < n && str . charAt ( index + 1 ) != ' b ' ) return false ; if ( index + 2 < n && str . charAt ( index + 2 ) == ' b ' ) return false ; if ( index == n - 1 ) return false ; index = str . indexOf ( " b " , index + 2 ) ; } return true ; } public static void main ( String [ ] args ) { String str = " abbaaabbabba " ; int n = str . length ( ) ; System . out . println ( isValidString ( str , n ) ) ; } }

Class/struct names: GFG
Java program:
class GfG { static boolean endsWith ( String str , String pat ) { int patLen = pat . length ( ) ; int strLen = str . length ( ) ; if ( patLen > strLen ) return false ; patLen -- ; strLen -- ; while ( patLen >= 0 ) { if ( pat . charAt ( patLen ) != str . charAt ( strLen ) ) return false ; patLen -- ; strLen -- ; } return true ; } static int countOfStrings ( String pat , int n , String sArr [ ] ) { int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( endsWith ( sArr [ i ] , pat ) ) count ++ ; } return count ; } public static void main ( String [ ] args ) { String pat = " ks " ; int n = 4 ; String sArr [ ] = { " geeks " , " geeksforgeeks " , " games " , " unit " } ; System . out . println ( countOfStrings ( pat , n , sArr ) ) ; } }

Index/key variables: i
Accumulator variables: count, i, patLen, strLen
Iterator variables: i
Class/struct names: GfG