import java.util.*; public class While3 { public static void main(String[] args) { System.out.println("Here is a simple game. You will roll a 6-sided die and move your piece on a board of\n" + "100 squares. You continue moving forward unless you land on any square whose number is divisible by 5\n" + "If you land on such a square, you move back 3 spaces. We will see how many rolls it takes to get to 100."); int die, square, count; char answer; Random generator=new Random(); Scanner in=new Scanner(System.in); do { square=0; count=0; while(square<100) { count++; die=generator.nextInt(6)+1; square=square+die; System.out.print("You rolled a " + die + " which moves you to position " + square + "."); if(square%5==0) { square=square-3; System.out.print(" You have landed on a 5th square, you are moved back to position " + square); } System.out.println(); } System.out.println("You finished the game in " + count + " turns"); System.out.print("Do you want to play again? "); answer=in.next().toLowerCase().charAt(0); } while(answer=='y'); System.out.println("Goodbye!"); } }