most repeated numbers in Java
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Hey!
You’ll probably want to use something like a
HashMap
to count occurrences.Here’s a great place to start: DigitalOcean’s Java tutorials. Super beginner-friendly and well-written!
- Bobby
Heya,
Here’s a simple Java program that finds the most repeated number(s) in an array of integers:
Sample Output:
It uses a
HashMap
to count how many times each number appears.Then it determines the maximum frequency and filters for numbers that appear that many times.
Let me know if you’d like a version that works with user input or with lists instead of arrays!