Java con números de declaración y al azar si

Jamal:

yo soy un principiante en Java y necesito ayuda para este bloque:

El problema que tengo es que aquí, cuando el número es inferior a 6 en el primer "if", que no te dan añadir a la puntuación al final. Sé que la cosa equivocada que estoy haciendo está en la segunda "if", i inicializar el marcador a 0, pero ¿cómo puedo hacerlo tanto del "if" se puede agregar a la puntuación cuando es superior a 6 y NO añadido cuando es inferior a 6? Cuando el número aleatorio es inferior a 6, que no se debe añadir a la partitura. No sé si estoy explaning bien, pero gracias por su tiempo!

int shot;
    int score = 0;
    shot = rand.nextInt(11);
    score += shot;

    if (shot > 6) {

        System.out.print("\nSHOT " + a + ".... Challenger shoots: " + shot);

        }
        else { 
            score = 0;
            System.out.print("\nSHOT " + a + ".... Challenger shoots: " +  "You missed the board!");
        }

    shot = rand.nextInt(11);
    score += shot;
    if (shot > 6) {
    System.out.print("\nSHOT " + (++a) + ".... Challenger shoots " + shot);
    }
    else {
        score = 0;
        System.out.print("\nSHOT " + (++a) + ".... Challenger shoots: " +  "You missed the board!");

    }

    System.out.print("\nCHALLENGER SCORE: " + score);
Arvind Kumar Avinash:

Puede hacerlo como

int score = 0;
int shot;

System.out.println("Shot#1:"); 
shot = rand.nextInt(11);
if (shot > 6) {
    score += shot;
    System.out.print("\nSHOT " + a + ".... Challenger shoots: " + shot);
} else {
    System.out.print("\nSHOT " + a + ".... Challenger shoots: You missed the board!");
}

System.out.println("Shot#2:"); 
shot = rand.nextInt(11);
if (shot > 6) {
    score += shot;
    System.out.print("\nSHOT " + (++a) + ".... Challenger shoots: " + shot);
} else {
    System.out.print("\nSHOT " + (++a) + ".... Challenger shoots: You missed the board!");
}

System.out.print("\nCHALLENGER SCORE: " + score);

Siéntase libre de comentar en caso de cualquier duda / problema.

Supongo que te gusta

Origin http://10.200.1.11:23101/article/api/json?id=394119&siteId=1
Recomendado
Clasificación