dhyuti-n/xlcost-variable-roles huggingface dataset:
Java program:
class CountSubString { int countSubStr ( char str [ ] , int n ) { int res = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( str [ i ] == '1' ) { for ( int j = i + 1 ; j < n ; j ++ ) { if ( str [ j ] == '1' ) res ++ ; } } } return res ; } public static void main ( String [ ] args ) { CountSubString count = new CountSubString ( ) ; String string = "00100101" ; char str [ ] = string . toCharArray ( ) ; int n = str . length ; System . out . println ( count . countSubStr ( str , n ) ) ; } }

Index/key variables: i, j
Accumulator variables: i, j, res
Iterator variables: i, j
Class/struct names: CountSubString
Java program:
import java . util . * ; class GFG { static char [ ] str ; static void reverse ( int low , int high ) { while ( low < high ) { char t = str [ low ] ; str [ low ] = str [ high ] ; str [ high ] = t ; ++ low ; -- high ; } } static void cycleLeader ( int shift , int len ) { int j ; char item ; for ( int i = 1 ; i < len ; i *= 3 ) { j = i ; item = str [ j + shift ] ; do { if ( j % 2 == 1 ) j = len / 2 + j / 2 ; else j /= 2 ; char t = str [ j + shift ] ; str [ j + shift ] = item ; item = t ; } while ( j != i ) ; } } static void moveNumberToSecondHalf ( ) { int k , lenFirst ; int lenRemaining = str . length ; int shift = 0 ; while ( lenRemaining > 0 ) { k = 0 ; while ( Math . pow ( 3 , k ) + 1 <= lenRemaining ) k ++ ; lenFirst = ( int ) Math . pow ( 3 , k - 1 ) + 1 ; lenRemaining -= lenFirst ; cycleLeader ( shift , lenFirst ) ; reverse ( shift / 2 , shift - 1 ) ; reverse ( shift , shift + lenFirst / 2 - 1 ) ; reverse ( shift / 2 , shift + lenFirst / 2 - 1 ) ; shift += lenFirst ; } } public static void main ( String [ ] args ) { String st = " a1b2c3d4e5f6g7" ; str = st . toCharArray ( ) ; moveNumberToSecondHalf ( ) ; System . out . print ( str ) ; } }

Index/key variables: high, low
Accumulator variables: i, j, k, lenRemaining, shift
Iterator variables: i
Class/struct names: GFG
Java program:
class Node { int data ; Node left , right ; public Node ( int item ) { data = item ; left = right = null ; } } class BinaryTree { Node root ; Node removeShortPathNodesUtil ( Node node , int level , int k ) { if ( node == null ) return null ; node . left = removeShortPathNodesUtil ( node . left , level + 1 , k ) ; node . right = removeShortPathNodesUtil ( node . right , level + 1 , k ) ; if ( node . left == null && node . right == null && level < k ) return null ; return node ; } Node removeShortPathNodes ( Node node , int k ) { int pathLen = 0 ; return removeShortPathNodesUtil ( node , 1 , k ) ; } void printInorder ( Node node ) { if ( node != null ) { printInorder ( node . left ) ; System . out . print ( node . data + " ▁ " ) ; printInorder ( node . right ) ; } } public static void main ( String args [ ] ) { BinaryTree tree = new BinaryTree ( ) ; int k = 4 ; tree . root = new Node ( 1 ) ; tree . root . left = new Node ( 2 ) ; tree . root . right = new Node ( 3 ) ; tree . root . left . left = new Node ( 4 ) ; tree . root . left . right = new Node ( 5 ) ; tree . root . left . left . left = new Node ( 7 ) ; tree . root . right . right = new Node ( 6 ) ; tree . root . right . right . left = new Node ( 8 ) ; System . out . println ( " The ▁ inorder ▁ traversal ▁ of ▁ original ▁ tree ▁ is ▁ : ▁ " ) ; tree . printInorder ( tree . root ) ; Node res = tree . removeShortPathNodes ( tree . root , k ) ; System . out . println ( " " ) ; System . out . println ( " The ▁ inorder ▁ traversal ▁ of ▁ modified ▁ tree ▁ is ▁ : ▁ " ) ; tree . printInorder ( res ) ; } }

Class/struct names: BinaryTree, Node
Java program:
import java . util . * ; class GFG { static void removeDuplicate ( char str [ ] , int n ) { HashSet < Character > s = new LinkedHashSet < > ( n - 1 ) ; for ( char x : str ) s . add ( x ) ; for ( char x : s ) System . out . print ( x ) ; } public static void main ( String [ ] args ) { char str [ ] = " geeksforgeeks " . toCharArray ( ) ; int n = str . length ; removeDuplicate ( str , n ) ; } }

Iterator variables: x
Class/struct names: GFG
Java program:
import java . io . * ; import java . lang . * ; import java . util . * ; class GFG { static int ROW ; static int COL ; static class Point { int x , y ; Point ( int x , int y ) { this . x = x ; this . y = y ; } } static class Node { Point pt ; int dist ; Node ( Point p , int dist ) { this . pt = p ; this . dist = dist ; } } static boolean isValid ( int row , int col ) { return ( row >= 0 ) && ( col >= 0 ) && ( row < ROW ) && ( col < COL ) ; } static int dRow [ ] = { - 1 , 0 , 0 , 1 } ; static int dCol [ ] = { 0 , - 1 , 1 , 0 } ; static void pathMoves ( char mat [ ] [ ] , Point src , Point dest ) { int d [ ] [ ] = new int [ ROW ] [ COL ] ; for ( int dd [ ] : d ) Arrays . fill ( dd , - 1 ) ; d [ src . x ] [ src . y ] = 0 ; boolean visited [ ] [ ] = new boolean [ ROW ] [ COL ] ; visited [ src . x ] [ src . y ] = true ; ArrayDeque < Node > q = new ArrayDeque < > ( ) ; Node s = new Node ( src , 0 ) ; q . addLast ( s ) ; boolean ok = false ; while ( ! q . isEmpty ( ) ) { Node curr = q . removeFirst ( ) ; Point pt = curr . pt ; if ( pt . x == dest . x && pt . y == dest . y ) { int xx = pt . x , yy = pt . y ; int dist = curr . dist ; d [ pt . x ] [ pt . y ] = dist ; String pathmoves = " " ; while ( xx != src . x yy != src . y ) { if ( xx > 0 && d [ xx - 1 ] [ yy ] == dist - 1 ) { pathmoves += ' D ' ; xx -- ; } if ( xx < ROW - 1 && d [ xx + 1 ] [ yy ] == dist - 1 ) { pathmoves += ' U ' ; xx ++ ; } if ( yy > 0 && d [ xx ] [ yy - 1 ] == dist - 1 ) { pathmoves += ' R ' ; yy -- ; } if ( yy < COL - 1 && d [ xx ] [ yy + 1 ] == dist - 1 ) { pathmoves += ' L ' ; yy ++ ; } dist -- ; } for ( int i = pathmoves . length ( ) - 1 ; i >= 0 ; -- i ) System . out . print ( pathmoves . charAt ( i ) ) ; ok = true ; break ; } if ( ! q . isEmpty ( ) ) q . removeFirst ( ) ; for ( int i = 0 ; i < 4 ; i ++ ) { int row = pt . x + dRow [ i ] ; int col = pt . y + dCol [ i ] ; if ( isValid ( row , col ) && ( mat [ row ] [ col ] == '1' mat [ row ] [ col ] == ' s ' mat [ row ] [ col ] == ' d ' ) && ! visited [ row ] [ col ] ) { visited [ row ] [ col ] = true ; Node adjCell = new Node ( new Point ( row , col ) , curr . dist + 1 ) ; q . addLast ( adjCell ) ; d [ row ] [ col ] = curr . dist + 1 ; } } } if ( ! ok ) System . out . println ( - 1 ) ; } public static void main ( String [ ] args ) { char mat [ ] [ ] = { { '0' , '1' , '0' , '1' } , { '1' , '0' , '1' , '1' } , { '0' , '1' , '1' , '1' } , { '1' , '1' , '1' , '0' } } ; ROW = mat . length ; COL = mat [ 0 ] . length ; Point src = new Point ( 0 , 3 ) ; Point dest = new Point ( 3 , 0 ) ; pathMoves ( mat , src , dest ) ; } }

Index/key variables: COL, ROW, col, i, row, xx, yy
Accumulator variables: dist, i, pathmoves, xx, yy
Iterator variables: i
Boolean variables: ok
Class/struct names: GFG, Node, Point
Java program:
class GFG { static boolean find ( double [ ] v , int n , double dest , String s ) { if ( n == 1 ) { if ( Math . abs ( v [ 0 ] - dest ) <= 0.0000001 ) { System . out . println ( s + String . valueOf ( ( int ) dest ) + " ▁ " ) ; return true ; } return false ; } for ( int i = 0 ; i < n ; i ++ ) { for ( int j = i + 1 ; j < n ; j ++ ) { double a = v [ i ] , b = v [ j ] ; String p = s ; v [ i ] = a + b ; v [ j ] = v [ n - 1 ] ; s = ( s + String . valueOf ( ( int ) a ) + ' + ' + String . valueOf ( ( int ) b ) + " ▁ = > ▁ " ) ; if ( find ( v , n - 1 , dest , s ) ) return true ; s = p ; v [ i ] = a - b ; v [ j ] = v [ n - 1 ] ; s = ( s + String . valueOf ( ( int ) a ) + ' - ' + String . valueOf ( ( int ) b ) + " ▁ = > ▁ " ) ; if ( find ( v , n - 1 , dest , s ) ) return true ; s = p ; v [ i ] = b - a ; v [ j ] = v [ n - 1 ] ; s = ( s + String . valueOf ( ( int ) b ) + ' - ' + String . valueOf ( ( int ) a ) + " ▁ = > ▁ " ) ; if ( find ( v , n - 1 , dest , s ) ) return true ; s = p ; v [ i ] = a * b ; v [ j ] = v [ n - 1 ] ; s = ( s + String . valueOf ( ( int ) a ) + ' * ' + String . valueOf ( ( int ) b ) + " ▁ = > ▁ " ) ; if ( find ( v , n - 1 , dest , s ) ) return true ; s = p ; if ( b != 0 ) { v [ i ] = a / b ; v [ j ] = v [ n - 1 ] ; s = ( s + String . valueOf ( ( int ) a ) + ' / ' + String . valueOf ( ( int ) b ) + " ▁ = > ▁ " ) ; if ( find ( v , n - 1 , dest , s ) ) return true ; } s = p ; if ( a != 0 ) { v [ i ] = b / a ; v [ j ] = v [ n - 1 ] ; s = ( s + String . valueOf ( ( int ) b ) + ' / ' + String . valueOf ( ( int ) a ) + " ▁ = > ▁ " ) ; if ( find ( v , n - 1 , dest , s ) ) return true ; } s = p ; v [ i ] = a ; v [ j ] = b ; } } return false ; } static void checkPossibleOperation ( double [ ] arr , double K ) { String s = " " ; if ( ! find ( arr , arr . length , K , s ) ) { System . out . println ( " - 1" ) ; } } public static void main ( String [ ] args ) { double [ ] arr = { 2 , 0 , 0 , 2 } ; double K = 4 ; checkPossibleOperation ( arr , K ) ; } }

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . Stack ; class Node { private int x , y ; private int dir ; public Node ( int i , int j ) { this . x = i ; this . y = j ; this . dir = 0 ; } public int getX ( ) { return x ; } public void setX ( int x ) { this . x = x ; } public int getY ( ) { return y ; } public void setY ( int y ) { this . y = y ; } public int getDir ( ) { return dir ; } public void setDir ( int dir ) { this . dir = dir ; } } public class RatInMaze { private static final int N = 4 ; private static final int M = 5 ; int n = N , m = M ; private static boolean [ ] [ ] visited = new boolean [ N ] [ M ] ; public static void main ( String [ ] args ) { setVisited ( true ) ; int maze [ ] [ ] = { { 1 , 0 , 1 , 1 , 0 } , { 1 , 1 , 1 , 0 , 1 } , { 0 , 1 , 0 , 1 , 1 } , { 1 , 1 , 1 , 1 , 1 } } ; if ( isReachable ( maze ) ) { System . out . println ( "Path Found!NEW_LINE"); } else System . out . println ( "No Path Found!NEW_LINE"); } private static void setVisited ( boolean b ) { for ( int i = 0 ; i < visited . length ; i ++ ) { for ( int j = 0 ; j < visited [ i ] . length ; j ++ ) { visited [ i ] [ j ] = b ; } } } private static boolean isReachable ( int maze [ ] [ ] ) { int i = 0 , j = 0 ; int fx , fy ; fx = 2 ; fy = 3 ; Stack < Node > s = new Stack < Node > ( ) ; Node temp = new Node ( i , j ) ; s . push ( temp ) ; while ( ! s . empty ( ) ) { temp = s . peek ( ) ; int d = temp . getDir ( ) ; i = temp . getX ( ) ; j = temp . getY ( ) ; temp . setDir ( temp . getDir ( ) + 1 ) ; s . pop ( ) ; s . push ( temp ) ; if ( i == fx && j == fy ) { return true ; } if ( d == 0 ) { if ( i - 1 >= 0 && maze [ i - 1 ] [ j ] == 1 && visited [ i - 1 ] [ j ] ) { Node temp1 = new Node ( i - 1 , j ) ; visited [ i - 1 ] [ j ] = false ; s . push ( temp1 ) ; } } else if ( d == 1 ) { if ( j - 1 >= 0 && maze [ i ] [ j - 1 ] == 1 && visited [ i ] [ j - 1 ] ) { Node temp1 = new Node ( i , j - 1 ) ; visited [ i ] [ j - 1 ] = false ; s . push ( temp1 ) ; } } else if ( d == 2 ) { if ( i + 1 < N && maze [ i + 1 ] [ j ] == 1 && visited [ i + 1 ] [ j ] ) { Node temp1 = new Node ( i + 1 , j ) ; visited [ i + 1 ] [ j ] = false ; s . push ( temp1 ) ; } } else if ( d == 3 ) { if ( j + 1 < M && maze [ i ] [ j + 1 ] == 1 && visited [ i ] [ j + 1 ] ) { Node temp1 = new Node ( i , j + 1 ) ; visited [ i ] [ j + 1 ] = false ; s . push ( temp1 ) ; } } else { visited [ temp . getX ( ) ] [ temp . getY ( ) ] = true ; s . pop ( ) ; } } return false ; } }

Index/key variables: M, N, i, j
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: Node, RatInMaze
Java program:
public class Suduko { static int N = 9 ; static void print ( int [ ] [ ] grid ) { for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < N ; j ++ ) System . out . print ( grid [ i ] [ j ] + " ▁ " ) ; System . out . println ( ) ; } } static boolean isSafe ( int [ ] [ ] grid , int row , int col , int num ) { for ( int x = 0 ; x <= 8 ; x ++ ) if ( grid [ row ] [ x ] == num ) return false ; for ( int x = 0 ; x <= 8 ; x ++ ) if ( grid [ x ] [ col ] == num ) return false ; int startRow = row - row % 3 , startCol = col - col % 3 ; for ( int i = 0 ; i < 3 ; i ++ ) for ( int j = 0 ; j < 3 ; j ++ ) if ( grid [ i + startRow ] [ j + startCol ] == num ) return false ; return true ; } static boolean solveSuduko ( int grid [ ] [ ] , int row , int col ) { if ( row == N - 1 && col == N ) return true ; if ( col == N ) { row ++ ; col = 0 ; } if ( grid [ row ] [ col ] != 0 ) return solveSuduko ( grid , row , col + 1 ) ; for ( int num = 1 ; num < 10 ; num ++ ) { if ( isSafe ( grid , row , col , num ) ) { grid [ row ] [ col ] = num ; if ( solveSuduko ( grid , row , col + 1 ) ) return true ; } grid [ row ] [ col ] = 0 ; } return false ; } public static void main ( String [ ] args ) { int grid [ ] [ ] = { { 3 , 0 , 6 , 5 , 0 , 8 , 4 , 0 , 0 } , { 5 , 2 , 0 , 0 , 0 , 0 , 0 , 0 , 0 } , { 0 , 8 , 7 , 0 , 0 , 0 , 0 , 3 , 1 } , { 0 , 0 , 3 , 0 , 1 , 0 , 0 , 8 , 0 } , { 9 , 0 , 0 , 8 , 6 , 3 , 0 , 0 , 5 } , { 0 , 5 , 0 , 0 , 9 , 0 , 6 , 0 , 0 } , { 1 , 3 , 0 , 0 , 0 , 0 , 2 , 5 , 0 } , { 0 , 0 , 0 , 0 , 0 , 0 , 0 , 7 , 4 } , { 0 , 0 , 5 , 2 , 0 , 6 , 3 , 0 , 0 } } ; if ( solveSuduko ( grid , 0 , 0 ) ) print ( grid ) ; else System . out . println ( " No ▁ Solution ▁ exists " ) ; } }

Index/key variables: col, i, j, row, x
Accumulator variables: i, j, num, row, x
Iterator variables: i, j, num, x
Class/struct names: Suduko
Java program:
import java . io . * ; import java . util . HashSet ; class PairSum { static void printpairs ( int arr [ ] , int sum ) { HashSet < Integer > s = new HashSet < Integer > ( ) ; for ( int i = 0 ; i < arr . length ; ++ i ) { int temp = sum - arr [ i ] ; if ( s . contains ( temp ) ) { System . out . println ( " Pair ▁ with ▁ given ▁ sum ▁ " + sum + " ▁ is ▁ ( " + arr [ i ] + " , ▁ " + temp + " ) " ) ; } s . add ( arr [ i ] ) ; } } public static void main ( String [ ] args ) { int A [ ] = { 1 , 4 , 45 , 6 , 10 , 8 } ; int n = 16 ; printpairs ( A , n ) ; } }

Index/key variables: i
Iterator variables: i
Class/struct names: PairSum
Java program:
class Node { int data ; Node left , right ; Node ( int item ) { data = item ; left = right = null ; } } class Result { int res = 0 ; } class BinaryTree { Node root ; private void longestConsecutiveUtil ( Node root , int curlength , int expected , Result res ) { if ( root == null ) return ; if ( root . data == expected ) curlength ++ ; else curlength = 1 ; res . res = Math . max ( res . res , curlength ) ; longestConsecutiveUtil ( root . left , curlength , root . data + 1 , res ) ; longestConsecutiveUtil ( root . right , curlength , root . data + 1 , res ) ; } int longestConsecutive ( Node root ) { if ( root == null ) return 0 ; Result res = new Result ( ) ; longestConsecutiveUtil ( root , 0 , root . data , res ) ; return res . res ; } public static void main ( String args [ ] ) { BinaryTree tree = new BinaryTree ( ) ; tree . root = new Node ( 6 ) ; tree . root . right = new Node ( 9 ) ; tree . root . right . left = new Node ( 7 ) ; tree . root . right . right = new Node ( 10 ) ; tree . root . right . right . right = new Node ( 11 ) ; System . out . println ( tree . longestConsecutive ( tree . root ) ) ; } }

Accumulator variables: curlength
Class/struct names: BinaryTree, Node, Result
Java program:
import java . io . * ; class GFG { static long power ( long x , long y , long p ) { long res = 1 ; x = x % p ; if ( x == 0 ) return 0 ; while ( y > 0 ) { if ( ( y & 1 ) == 1 ) res = ( res * x ) % p ; y = y >> 1 ; x = ( x * x ) % p ; } return res ; } static long remainder ( long n , long a , long p ) { long ans = a % p ; for ( long i = 1 ; i <= n ; i ++ ) ans = power ( ans , i , p ) ; return ans ; } public static void main ( String [ ] args ) { long A = 2 , N = 1 , P = 2 ; System . out . println ( remainder ( N , A , P ) ) ; } }

Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static void findMajority ( int arr [ ] , int n ) { int count1 = 0 , count2 = 0 ; int flag = 0 ; int first = Integer . MIN_VALUE ; ; int second = Integer . MAX_VALUE ; for ( int i = 0 ; i < n ; i ++ ) { if ( first == arr [ i ] ) count1 ++ ; else if ( second == arr [ i ] ) count2 ++ ; else if ( count1 == 0 ) { count1 ++ ; first = arr [ i ] ; } else if ( count2 == 0 ) { count2 ++ ; second = arr [ i ] ; } else { count1 -- ; count2 -- ; } } count1 = 0 ; count2 = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] == first ) count1 ++ ; else if ( arr [ i ] == second ) count2 ++ ; } if ( count1 > n / 3 ) { System . out . print ( first + " ▁ " ) ; flag = 1 ; } if ( count2 > n / 3 ) { System . out . print ( second + " ▁ " ) ; flag = 1 ; } if ( flag == 0 ) System . out . println ( " No ▁ Majority ▁ Element " ) ; } public static void main ( String args [ ] ) { int arr [ ] = { 2 , 2 , 3 , 1 , 3 , 2 , 1 , 1 } ; int n = arr . length ; findMajority ( arr , n ) ; } }

Index/key variables: i
Accumulator variables: count1, count2, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static class pair { int first , second ; public pair ( int first , int second ) { this . first = first ; this . second = second ; } } static pair Multiply ( pair p , pair q , int M ) { int x = ( ( p . first * q . first ) % M - ( p . second * q . second ) % M + M ) % M ; int y = ( ( p . first * q . second ) % M + ( p . second * q . first ) % M ) % M ; return new pair ( x , y ) ; } static pair compPow ( pair complex , int k , int M ) { pair res = new pair ( 1 , 0 ) ; while ( k > 0 ) { if ( k % 2 == 1 ) { res = Multiply ( res , complex , M ) ; } complex = Multiply ( complex , complex , M ) ; k = k >> 1 ; } return res ; } public static void main ( String [ ] args ) { int A = 7 , B = 3 , k = 10 , M = 97 ; pair ans = compPow ( new pair ( A , B ) , k , M ) ; System . out . println ( ans . first + " ▁ + ▁ i " + ans . second ) ; } }

Class/struct names: GFG, pair
Java program:
class GFG { static class pair { int first , second ; public pair ( int first , int second ) { this . first = first ; this . second = second ; } } static final int seg_max = 51 ; static pair [ ] seg_tree = new pair [ seg_max ] ; static int n ; static pair buildMaxTree ( int l , int r , int i , int arr [ ] ) { if ( l == r ) { seg_tree [ i ] = new pair ( arr [ l ] , l ) ; return seg_tree [ i ] ; } seg_tree [ i ] = max ( buildMaxTree ( l , ( l + r ) / 2 , 2 * i + 1 , arr ) , buildMaxTree ( ( l + r ) / 2 + 1 , r , 2 * i + 2 , arr ) ) ; return seg_tree [ i ] ; } static pair rangeMax ( int l , int r , int arr [ ] , int i , int sl , int sr ) { if ( sr < l sl > r ) return new pair ( Integer . MIN_VALUE , - 1 ) ; if ( sl >= l && sr <= r ) return seg_tree [ i ] ; return max ( rangeMax ( l , r , arr , 2 * i + 1 , sl , ( sl + sr ) / 2 ) , rangeMax ( l , r , arr , 2 * i + 2 , ( sl + sr ) / 2 + 1 , sr ) ) ; } static pair max ( pair f , pair s ) { if ( f . first > s . first ) return f ; else return s ; } static int maxSumSubarray ( int arr [ ] , int l , int r ) { if ( l > r ) return 0 ; pair a = rangeMax ( l , r , arr , 0 , 0 , n - 1 ) ; return a . first * ( r - a . second + 1 ) * ( a . second - l + 1 ) + maxSumSubarray ( arr , l , a . second - 1 ) + maxSumSubarray ( arr , a . second + 1 , r ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 3 , 1 , 7 } ; n = arr . length ; buildMaxTree ( 0 , n - 1 , 0 , arr ) ; System . out . print ( maxSumSubarray ( arr , 0 , n - 1 ) ) ; } }

Index/key variables: i, l, seg_max
Class/struct names: GFG, pair
Java program:
import java . io . * ; class GFG { static int exponentMod ( int A , int B , int C ) { if ( A == 0 ) return 0 ; if ( B == 0 ) return 1 ; long y ; if ( B % 2 == 0 ) { y = exponentMod ( A , B / 2 , C ) ; y = ( y * y ) % C ; } else { y = A % C ; y = ( y * exponentMod ( A , B - 1 , C ) % C ) % C ; } return ( int ) ( ( y + C ) % C ) ; } public static void main ( String args [ ] ) { int A = 2 , B = 5 , C = 13 ; System . out . println ( " Power ▁ is ▁ " + exponentMod ( A , B , C ) ) ; } }

Class/struct names: GFG
Java program:
function void findFrequencies ( ele ) { var freq = 1 ; var idx = 1 ; var element = ele [ 0 ] ; while ( idx < ele . length ) { if ( ele [ idx - 1 ] == ele [ idx ] ) { freq ++ ; idx ++ ; } else { document . write ( element + " ▁ " + freq + " < br > " ) ; element = ele [ idx ] ; idx ++ ; freq = 1 ; } } document . write ( element + " ▁ " + freq + " < br > " ) ; } document . write ( " - - - frequencies ▁ in ▁ a ▁ sorted ▁ array - - - - " + " < br > " ) ; findFrequencies ( new Array ( 10 , 20 , 30 , 30 , 30 , 40 , 50 , 50 , 50 , 50 , 70 ) ) ;

Index/key variables: idx
Accumulator variables: freq, idx
Java program:
import java . io . * ; class GFG { static int power ( int x , int y , int p ) { int res = 1 x = x % p ; if ( x == 0 ) return 0 ; while ( y > 0 ) { if ( ( y & 1 ) != 0 ) res = ( res * x ) % p ; y = y >> 1 ; y = y / 2 x = ( x * x ) % p ; } return res ; } public static void main ( String [ ] args ) { int x = 2 ; int y = 5 ; int p = 13 ; System . out . print ( " Power ▁ is ▁ " + power ( x , y , p ) ) ; } }

Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static class Node { int key ; Node left ; Node right ; } ; static Node newNode ( int key ) { Node node = new Node ( ) ; node . left = null ; node . right = null ; node . key = key ; return node ; } static int maxBends ; static int len ; static void findMaxBendsUtil ( Node node , char dir , int bends , int soFar ) { if ( node == null ) return ; if ( node . left == null && node . right == null ) { if ( bends > maxBends ) { maxBends = bends ; len = soFar ; } } else { if ( dir == ' l ' ) { findMaxBendsUtil ( node . left , dir , bends , soFar + 1 ) ; findMaxBendsUtil ( node . right , ' r ' , bends + 1 , soFar + 1 ) ; } else { findMaxBendsUtil ( node . right , dir , bends , soFar + 1 ) ; findMaxBendsUtil ( node . left , ' l ' , bends + 1 , soFar + 1 ) ; } } } static int findMaxBends ( Node node ) { if ( node == null ) return 0 ; len = 0 ; maxBends = - 1 ; int bends = 0 ; if ( node . left != null ) findMaxBendsUtil ( node . left , ' l ' , bends , 1 ) ; if ( node . right != null ) findMaxBendsUtil ( node . right , ' r ' , bends , 1 ) ; len ++ ; return len ; } public static void main ( String [ ] args ) { Node root = newNode ( 10 ) ; root . left = newNode ( 8 ) ; root . right = newNode ( 2 ) ; root . left . left = newNode ( 3 ) ; root . left . right = newNode ( 5 ) ; root . right . left = newNode ( 2 ) ; root . right . left . right = newNode ( 1 ) ; root . right . left . right . left = newNode ( 9 ) ; System . out . print ( findMaxBends ( root ) - 1 ) ; } }

Accumulator variables: len
Class/struct names: GFG, Node
Java program:
class GFG { static double magnitude ( double arr [ ] , int N ) { double magnitude = 0 ; for ( int i = 0 ; i < N ; i ++ ) magnitude += arr [ i ] * arr [ i ] ; return Math . sqrt ( magnitude ) ; } static double dotProduct ( double [ ] arr , double [ ] brr , int N ) { double product = 0 ; for ( int i = 0 ; i < N ; i ++ ) product = product + arr [ i ] * brr [ i ] ; return product ; } static void angleBetweenVectors ( double [ ] arr , double [ ] brr , int N ) { double dotProductOfVectors = dotProduct ( arr , brr , N ) ; double magnitudeOfA = magnitude ( arr , N ) ; double magnitudeOfB = magnitude ( brr , N ) ; double angle = dotProductOfVectors / ( magnitudeOfA * magnitudeOfB ) ; System . out . println ( angle ) ; } public static void main ( String [ ] args ) { double [ ] arr = { - 0.5 , - 2 , 1 } ; double [ ] brr = { - 1 , - 1 , 0.3 } ; int N = arr . length ; angleBetweenVectors ( arr , brr , N ) ; } }

Index/key variables: i
Accumulator variables: i, magnitude
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; import java . util . * ; class GFG { static void secondary_polygon ( int Angle ) { int edges_primary = 360 / Angle ; if ( edges_primary >= 6 ) { int edges_max_secondary = edges_primary / 2 ; System . out . println ( edges_max_secondary + 3 ) ; } else System . out . println ( " Not ▁ Possible " ) ; } public static void main ( String [ ] args ) { int Angle = 45 ; secondary_polygon ( Angle ) ; } }

Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static double circleArea ( double r ) { double pi = 3.14159265358979323846 ; return ( pi * r * r ) ; } static double findCircleAreaByMedian ( int m ) { double r = 2 * m / 3 ; return circleArea ( r ) ; } public static void main ( String args [ ] ) { int m = 3 ; System . out . printf ( " % .4f " , findCircleAreaByMedian ( m ) ) ; } }

Class/struct names: GFG