Buggy code:
public class BalancedPartition { public static boolean isForeverLoop = false ; public static boolean isAllZeroCase = false ; public static boolean isAllZeroNegativeCase = false ; public static boolean isOneSideZeroNegativeCase = false ; public static boolean isLoopCase = false ; GraphNode NodeWithMaxSCB = new GraphNode ( ) ; ArrayList < GraphNode > NodeList = new ArrayList < GraphNode > ( ) ; int NodeSize ; int MaxDiff = 1 ; int turnForServer = - 1 ; int NumNodeServer0 = 0 ; int NumNodeServer1 = 0 ; public static int MaxLoopCount = 1000 ; private int totalReplicaCount ; public BalancedPartition ( ) { } public BalancedPartition ( ArrayList < GraphNode > myArrayList ) { } public void setNumNodeServer0 ( int NumNodeServer0 ) { } public void setNumNodeServer1 ( int NumNodeServer1 ) { } public int getNumNodeServer0 ( ) { } public int getNumNodeServer1 ( ) { } public void setMaxDiff ( int TotalNodes ) { } public void FindPartition ( ) { System . out . println ( ( "Total<seq2seq4repair_space>Replicas<seq2seq4repair_space>Before<seq2seq4repair_space>Applying<seq2seq4repair_space>Algo:<seq2seq4repair_space>" + ( returnReplicas ( NodeList ) ) ) ) ; NodeSize = NodeList . size ( ) ; setNumNodeServer1 ( getNodeCounts ( NodeList ) ) ; setNumNodeServer0 ( ( ( NodeSize ) - ( getNumNodeServer1 ( ) ) ) ) ; System . out . println ( ( ( ( "Total<seq2seq4repair_space>Node<seq2seq4repair_space>Size<seq2seq4repair_space>in<seq2seq4repair_space>Server<seq2seq4repair_space>0:<seq2seq4repair_space>" + ( getNumNodeServer0 ( ) ) ) + "<seq2seq4repair_space>Total<seq2seq4repair_space>Node<seq2seq4repair_space>Size<seq2seq4repair_space>in<seq2seq4repair_space>Server<seq2seq4repair_space>1:<seq2seq4repair_space>" ) + ( getNumNodeServer1 ( ) ) ) ) ; int NumNodesDiff = 0 ; <START_BUG> for ( int j = 0 ; j < ( ( ( NodeSize ) // 2 ) + ( ( ( this . NodeSize ) % 2 ) - 1 ) ) ; j ++ ) { <END_BUG> this . FindNodeWithMaxSCB ( NodeList , 0 ) ; this . RunAlgorithm ( ) ; this . printAllNodeDetails ( NodeList ) ; setNumNodeServer1 ( ( ( getNumNodeServer1 ( ) ) + 1 ) ) ; setNumNodeServer0 ( ( ( getNumNodeServer0 ( ) ) - 1 ) ) ; NumNodesDiff = Math . abs ( ( ( getNumNodeServer1 ( ) ) - ( getNumNodeServer0 ( ) ) ) ) ; System . out . println ( ( "Node<seq2seq4repair_space>Difference:<seq2seq4repair_space>" + NumNodesDiff ) ) ; System . out . println ( ( "Num<seq2seq4repair_space>Replicas:<seq2seq4repair_space>" + ( this . returnReplicas ( NodeList ) ) ) ) ; } System . out . println ( ( "Total<seq2seq4repair_space>Node<seq2seq4repair_space>Size:<seq2seq4repair_space>" + ( NodeSize ) ) ) ; System . out . println ( ( "Total<seq2seq4repair_space>Node<seq2seq4repair_space>Size<seq2seq4repair_space>0:<seq2seq4repair_space>" + ( getNumNodeServer0 ( ) ) ) ) ; System . out . println ( ( "Total<seq2seq4repair_space>Node<seq2seq4repair_space>Size<seq2seq4repair_space>1:<seq2seq4repair_space>" + ( getNumNodeServer1 ( ) ) ) ) ; turnForServer = 0 ; this . setMaxDiff ( NodeSize ) ; int LoopCnt = 0 ; while ( ( this . DetermineFinalState ( NodeList ) ) != true ) { NumNodesDiff = Math . abs ( ( ( getNumNodeServer1 ( ) ) - ( getNumNodeServer0 ( ) ) ) ) ; System . out . println ( ( "Node<seq2seq4repair_space>Difference<seq2seq4repair_space>Inside<seq2seq4repair_space>Loop:<seq2seq4repair_space>" + NumNodesDiff ) ) ; if ( NumNodesDiff <= ( this . MaxDiff ) ) { if ( ( turnForServer ) == 1 ) { this . FindNodeWithMaxSCB ( NodeList , 1 ) ; this . RunAlgorithm ( ) ; this . printAllNodeDetails ( NodeList ) ; setNumNodeServer1 ( ( ( getNumNodeServer1 ( ) ) - 1 ) ) ; setNumNodeServer0 ( ( ( getNumNodeServer0 ( ) ) + 1 ) ) ; NumNodesDiff = Math . abs ( ( ( getNumNodeServer1 ( ) ) - ( getNumNodeServer0 ( ) ) ) ) ; turnForServer = 0 ; LoopCnt ++ ; } else { this . FindNodeWithMaxSCB ( NodeList , 0 ) ; this . RunAlgorithm ( ) ; this . printAllNodeDetails ( NodeList ) ; setNumNodeServer0 ( ( ( getNumNodeServer0 ( ) ) - 1 ) ) ; setNumNodeServer1 ( ( ( getNumNodeServer1 ( ) ) + 1 ) ) ; NumNodesDiff = Math . abs ( ( ( getNumNodeServer1 ( ) ) - ( getNumNodeServer0 ( ) ) ) ) ; turnForServer = 1 ; LoopCnt ++ ; } System . out . println ( ( ( ( "Server<seq2seq4repair_space>0<seq2seq4repair_space>Size:" + ( getNumNodeServer0 ( ) ) ) + "<seq2seq4repair_space>Num<seq2seq4repair_space>Replicas:<seq2seq4repair_space>" ) + ( this . returnReplicas ( NodeList ) ) ) ) ; } if ( LoopCnt > ( BalancedPartition . MaxLoopCount ) ) { BalancedPartition . isForeverLoop = true ; break ; } } System . out . println ( ( ( ( ( ( "Total<seq2seq4repair_space>Node<seq2seq4repair_space>Size:<seq2seq4repair_space>" + ( NodeSize ) ) + "<seq2seq4repair_space>Node<seq2seq4repair_space>Size<seq2seq4repair_space>Server<seq2seq4repair_space>0:<seq2seq4repair_space>" ) + ( getNumNodeServer0 ( ) ) ) + "<seq2seq4repair_space>Node<seq2seq4repair_space>Size<seq2seq4repair_space>Server<seq2seq4repair_space>1:<seq2seq4repair_space>" ) + ( getNumNodeServer1 ( ) ) ) ) ; System . out . println ( ( ( ( "Total<seq2seq4repair_space>Replicas<seq2seq4repair_space>After<seq2seq4repair_space>Applying<seq2seq4repair_space>Algorithm:<seq2seq4repair_space>" + ( this . returnReplicas ( NodeList ) ) ) + "<seq2seq4repair_space>Total<seq2seq4repair_space>Loop<seq2seq4repair_space>Counts:<seq2seq4repair_space>" ) + LoopCnt ) ) ; this . totalReplicaCount = this . returnReplicas ( NodeList ) ; if ( LoopCnt > 0 ) { BalancedPartition . isLoopCase = true ; } } public int replicaCount ( ) { } public void FindNodeWithMaxSCB ( ArrayList < GraphNode > myNodeList , int ServerID ) { } public void UpdateMyNeighbors ( GraphNode MyNode , boolean TargetNode ) { } public void RunAlgorithm ( ) { } public boolean CheckSCBNeighbors ( GraphNode myNode ) { } public boolean checkForAllZeros ( ArrayList < GraphNode > myNodeList ) { } public boolean checkForZeroAndNegativeSCB ( ArrayList < GraphNode > myNodeList ) { } public boolean DetermineFinalState ( ArrayList < GraphNode > myNodeList ) { } public int getNodeCounts ( ArrayList < GraphNode > myNodeList ) { } public void resetReplicas ( ArrayList < GraphNode > NodeList ) { } public int returnReplicas ( ArrayList < GraphNode > NodeList ) { } public void printAllNodeDetails ( ArrayList < GraphNode > NodeList ) { } }

Fix:
for ( int j = 1 ; j <= ( ( NodeSize ) // 2 ) ; j ++ ) {