diff --git a/src/main/java/com/thealgorithms/greedyalgorithms/FractionalKnapsack.java b/src/main/java/com/thealgorithms/greedyalgorithms/FractionalKnapsack.java index c5570f35c004..f46364fc704b 100644 --- a/src/main/java/com/thealgorithms/greedyalgorithms/FractionalKnapsack.java +++ b/src/main/java/com/thealgorithms/greedyalgorithms/FractionalKnapsack.java @@ -32,7 +32,7 @@ public static int fractionalKnapsack(int weight[], int value[], int capacity) { current -= weight[index]; } else { // If only a fraction of the item can fit, add a proportionate value. - finalValue += ratio[i][1] * current; + finalValue += (int) (ratio[i][1] * current); break; // Stop adding items to the knapsack since it's full. } }