lundi 29 juin 2020

Java- "For" Loops condition to end at user input

I am a beginner, I am trying to write a code that Loops or generates a random to the amount of times user input specifies. What I currently have is a random that loops to a condition I set to a number just so I don't have infinite outputs. I would like to create a condition that stops at the user's input integer amount. Example, user input how many times they would like to play and the computer randomly outputs only that amount of times. Below is what I have so far. numberOfFlips is my scanner integer of user's input.

    for (numberOfFlips =1; numberOfFlips < 10; numberOfFlips++) {
    
    //Computer generates a pick
     compGuess= rand.nextInt(2);
     
    //Computer generates a pick
     }
        if (compGuess== 0) { 
            System.out.println("Heads");
        } else {System.out.println ("Tails");



Aucun commentaire:

Enregistrer un commentaire