Answer to Question #279818 in Java | JSP | JSF for Hab1bti

Question #279818

D.



If



they



rolled



a



1,



set



their



score



for



the



round



to



zero



and



don’t



let



them



roll



again.



E.



If they rolled anything other than a 1, add that number to their round score and



ask if they want to roll again. If so, repeate the last two steps.



1
Expert's answer
2021-12-17T06:52:30-0500
import java.util.Random;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        int[] scores = new int[2];
        Scanner in = new Scanner(System.in);
        Random random = new Random();
        int cur = 0;
        int roll;
        while (true) {
            roll = random.nextInt(100) + 1;
            System.out.println("Roll(" + cur + "): " + roll);
            if (roll == 1) {
                scores[cur] = 0;
                System.out.println("Score(" + cur + "): " + scores[cur]);
            } else {
                scores[cur] += roll;
                System.out.println("Score(" + cur + "): " + scores[cur]);
                System.out.println("Again( Y | * ): ");
                if (!in.nextLine().equalsIgnoreCase("y")) {
                    cur = (cur + 1) % 2;
                }
            }
        }
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog