© Ron Dai 2019
R. DaiLearn Java with Mathhttps://doi.org/10.1007/978-1-4842-5209-3_21

21. Counting

Ron Dai1 
Seattle, WA, USA

We have learned many mathematical methods to solve counting problems. Some of these problems require a deep understanding of permutation and combination. In this chapter, we will learn examples of how to use programming to solve counting problems.


Tickets on a bus were $4.00 and $6.00. A total of 45 tickets were sold and $230 was earned. How many $4.00 tickets were sold? (2007/MathIsCool problem at http://academicsarecool.com)


This can be solved by a single loop. We set the variable tickets as the number of $4.00 tickets. Because the total number of tickets is 45, the number of $4.00 tickets cannot be greater ...

Get Learn Java with Math: Using Fun Projects and Games now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.