Advertisement
bobo_bobkata

Untitled

Oct 16th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. public static void main(String[] args) {
  2. int[] mas = {1, 1, 5, 5};
  3. int maxCount = 0;
  4. String maxNumCount = "none";
  5. for (int i = 0; i < mas.length; i++) {
  6. int count = 0;
  7. for (int j = 0; j < mas.length; j++) {
  8. if (mas[i] == mas[j]) {
  9. count++;
  10. }
  11. }
  12. if (count > maxCount) {
  13. maxCount = count;
  14. maxNumCount = "" + mas[i];
  15. } else if (count == maxCount && !maxNumCount.equals("" + mas[i])) {
  16. maxNumCount = "none";
  17. maxCount = count;
  18. }
  19. }
  20. if (maxNumCount.equals("none")) {
  21. System.out.println(0);
  22. } else {
  23. System.out.println(maxCount);
  24. }
  25. System.out.println(maxNumCount);
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement