Java – Exam Problem – Beers Count

After a week or so, I have started to master Java, as a part of the courses at the SoftUni. Today, I tried to resolve one of the problems, given about 3 weeks ago at the exam – CountBeers.
images
The problem is a bit trivial and very similar to the video length problem, discussed here. Long story short, you have the following input from the console:

41 beers
1 stacks
19 beers
End

Then you simply should calculate the number of beers, multiplying by 20, for each stack. I used some of the code from the previous problem, and I managed to come up with this:

It is really easy, once you manage to use the “while(true)” loop correctly and to split the beers string into integer and string. The third part of the solution is the usage of the operator “%”, which is quite OK. The hard-coding of the example is not really a best practise, but I think it is OK for the goal.

Last but not least, you may take a look at the original solution of the problem:

🙂

About

VBA Developer

Tagged with: , ,