How can I formulate this? (numbers) 1 * 8 *

1

I wanted to implement in java but I do not know how to compare two numbers but, if one digit is wrong that the other put in its place "*" so that 1994 to 1224 would be the result 1 ** 4, not how to do this since I can not decompose the number and put * as it would be possible with String, but I can not use it

Ex. if the secret number is 3245, it should appear initially * * * *, before asking for the first number.

If the number entered were 1255, it should show * 2 * 5, and so on.

To compare it I have to break it down dividing and finding the module

public class practica1 {

public static void main(String[] args) {
    // Entorno:
    // Los datos tipo short deberían de ser byte
    short numeroIncognita;
    short contador;
    short numeroComparar;
    short bandera = 0;

    // Algoritmo:
    System.out.println("Es el turno de la primera persona");
    do {
        System.out.println("Escriba un número entre 1 y 100 inclusive");
        numeroIncognita = Leer.datoShort();
    } while (numeroIncognita < 1 | numeroIncognita > 100);
    System.out.println("Es el turno de la segunda persona, usted tiene 10 oportunidades");
    for (contador = 1; contador <= 10; contador++) {

        System.out.println("Ingrese un número para  comparar con el número a adivinar, entre 1 y 100 inclusive");
        numeroComparar = Leer.datoShort();

        if (numeroComparar < numeroIncognita) {
            System.out.println("El número ingresado es menor que el número a adivinar");
        } else {
            if (numeroComparar == numeroIncognita) {
                contador = 10;
                bandera = 1;
            } else {
                System.out.println("El número ingresado es mayor que el numero a adivinar");
            }
        }

    }

    if (bandera == 1) {
        System.out.println("Usted ha adivinado el numero");
    } else {
        System.out.println("Usted no ha logrado adivinar el número");
    }
}

}

    
asked by user7407723 08.10.2017 в 02:32
source

1 answer

0

I do not understand why you can not pass the number to string? Pass it to string:

int numero = 1234; String cadena = ""; cadena = String.valueOf(numero); cadena= Integer.toString(numero);

And compare character by character to see if there are matches. If there is, you leave the original character that represents the number, if not, you step with '*'.

    
answered by 08.10.2017 в 04:27