Java program to optimize amount of money you can spend on different items to maximize value

So I am trying to design an algorithm to calculate the specific items I can buy, based on the amount of money I have, to get the most value of the purchase, given that each item has specific value. So my plan was to use nested if else statements etc… But that is extremely inefficient. Any input?

I am not asking for anyone to solve this for me. I am simply asking if this way is one of the least efficient but still successful way of doing it.


It sounds like you’re trying to implement the Knapsack problem.

You can read about it here:

Leave a Reply

Your email address will not be published. Required fields are marked *