-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrepeated_numbers.java
More file actions
32 lines (27 loc) · 885 Bytes
/
repeated_numbers.java
File metadata and controls
32 lines (27 loc) · 885 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package com.company;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Hashtable;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
System.out.println("enter the numbers : ");
Scanner sc = new Scanner(System.in);
String[] numbers = sc.next().split("");
Hashtable<Integer, Integer> dict = new Hashtable<Integer, Integer>();
for (int i = 0; i < 10; i++) {
int count = repeatedCountNumber(i, numbers);
if (count > 0) {
dict.put(i, count);
}
}
System.out.println(dict);
}
public static Integer repeatedCountNumber(int i, String[] numbers) {
int counter = 0;
for (String number : numbers) {
if (Integer.parseInt(number) == i) counter++;
}
return counter;
}
}