-
Notifications
You must be signed in to change notification settings - Fork 127
Open
Description
Hi could you plz take a look at my code, I tried to solve 'Roll the die game' exercise by myself. I would really appreciate your feedback on my beginner java journey with your course, ty.
package testAU.chapter4;
import java.util.Random;
public class RollTheDieGame {
public static void main(String args[]) {
int spaces = 20;
int totalSpaces = 0;
int leftSpaces;
int maxRolls = 5;
System.out.println("Welcome to the game 'Roll the Die!!!' Let's begin...");
for (int i = 0; i < maxRolls; i++) {
Random random = new Random();
int die = random.nextInt(6) + 1;
totalSpaces = totalSpaces + die;
leftSpaces = spaces - totalSpaces;
System.out.println("Roll # " + (i + 1) + ": You've rolled a " + die + ". " +
"You are now on space " + totalSpaces + " and have "
+ leftSpaces + " more to go.");
}
if (totalSpaces == 20) {
System.out.println("Congrats you won the game!!!");
} else {
System.out.println("Oops you lost the game, try again!!!");
}
}
}
Metadata
Metadata
Assignees
Labels
No labels