Dear community, I would like support in solving this algorithm:
Enter any natural number, to show the figures that are repeated and the number of times they are repeated. Example:
Ingrese un número natural cualquiera: 471757347
El numero 4: se repite 2 Veces
El numero 7: se repite 4 Veces
I have been able to get the largest or smallest number but only the two, in case of three or four repeated numbers I do not get to solve them. I await your guidance to solve this problem. Thanks.
This is the code I have so far:
public static void main(String[] args) {
Scanner linea = new Scanner(System.in);
int n, digito, digito1, repetir;
System.out.print("Introduce un número entero: ");
n = linea.nextInt();
repetir = 0;
digito1 = 0;
do {
digito = n % 10;
if (digito > digito1) {
digito1 = digito;
repetir = 1;
} else {
if (digito == digito1) {
repetir++;
}
}
n = n / 10;
} while (n != 0);
System.out.println("El numero " + digito1 + " se repite " + repetir + " veces");
}