In the below code.
package com.gmt.multithreading;
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class BearAndLadder {
public static int GetJumpCount(int jump,int slip,int[] walls)
{
int totalJumps = 0;
int numWalls = walls.length;
for (int i=0; i< numWalls; i++) {
int jumps = computeJumps(jump, slip, walls[i]);
totalJumps += jumps;
}
return totalJumps;
}
private static int computeJumps(int jump, int slip, int heightWall) {
int count = 0;
int effectiveHeight = (jump - slip);
while (heightWall < jump ) {
count = count + 1;
heightWall = (heightWall - effectiveHeight);
}
count = count + 1;
return count;
}
public static void main(String[] args) {
int [] walls = {6, 9 ,11, 4, 5};
System.out.println(GetJumpCount(4, 1, walls));
}
}
The integer comparison in while loop never return true. Clearly 6 > 4 , 9 > 4 but the code never executes the while part.
Aucun commentaire:
Enregistrer un commentaire