I'm very new to java, so i need a help . here is my problem:
I have two weights 1gram and 5 gram. now user will give the weight he/she wants to calculate, and the user will also give the count for 1gram and 5 gram. the program will return true if it can calculate otherwise it will return false. I’m giving you a example:
count for 1 gram is 5(say)
count for 5 gram is 3(say)
weight to measure the 12 gram
by using two 1gram and two 5gram i can make 12gram. so it will return true.
please help me to do this.
Thanks in advance.
As this is homework so here are hints for the algorithm for solution
Addition way
First you should take out multiples of 5 from the weight to be measured.
Remainder weight should be equal to number of 1 gram weights.
For example:
If these numbers are less than number of weights you have you have the answer.
Subtraction Way
First you should take out multiples of 5 from the weight to be measured.
For example:
Since you don’t have enough weights to do so then you can look if you can manage the remainder with 1 additional 5gm and remaining
5-1gm weightsi.e.1x5gmand5-3=2x1gm weightsso the answer will be3x5gmand2x1gm