Advertisement
Guest User

pro4

a guest
Nov 13th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. public static void problem_4() {
  2. /*
  3. Modify your solution of number 3. Take 10 numbers within 0 to 9. When
  4. you print output, users will see only the numbers that appeared at
  5. least twice and less than 5 times. e.g. Imagine the user entered
  6. 4,3,2,5,2,3,2,0,2,3 then the output is 3, 2.
  7.  
  8. */
  9. //USING COUNT
  10. //WITH RANGE
  11. Scanner tuna = new Scanner(System.in);
  12. int n, i, j, count = 0;
  13. //boolean flag = true;
  14. int[] arr = new int[10];
  15. //number = tuna.nextInt();
  16. System.out.println("Enter 10 numbers:");
  17.  
  18. for (i = 0; i < 10; i++) {
  19. n = tuna.nextInt();
  20. arr[n]++;
  21. //count = 1;
  22. if (arr[n] >= 2 && arr[n] < 5) {
  23.  
  24. if (arr[n] == 2 && arr[n] < 5) {
  25. System.out.println(n);
  26.  
  27. }
  28. }
  29. }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement