Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void problem_4() {
- /*
- Modify your solution of number 3. Take 10 numbers within 0 to 9. When
- you print output, users will see only the numbers that appeared at
- least twice and less than 5 times. e.g. Imagine the user entered
- 4,3,2,5,2,3,2,0,2,3 then the output is 3, 2.
- */
- //USING COUNT
- //WITH RANGE
- Scanner tuna = new Scanner(System.in);
- int n, i, j, count = 0;
- //boolean flag = true;
- int[] arr = new int[10];
- //number = tuna.nextInt();
- System.out.println("Enter 10 numbers:");
- for (i = 0; i < 10; i++) {
- n = tuna.nextInt();
- arr[n]++;
- //count = 1;
- if (arr[n] >= 2 && arr[n] < 5) {
- if (arr[n] == 2 && arr[n] < 5) {
- System.out.println(n);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement