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.
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;
}
}
}
}
}
Comments
Leave a comment