So, give me a number (1-10) and I will roll a 10 sided dice. I will continue to roll the dice until I have landed on your number 5 times and tell you how many iterations it took. I am trying to make a loop to represent this scenario and I am not sure what I have done wrong. Here is the code I have written so far:

Code :

int x = 1; for(int i = 0;; i++) { int rNum = (int) (Math.random() * 10) + 1; if (rNum == val) //val is the given number { x++; } if (x == 5) { System.out.println(rNum); break; } }

So far the output is just one number, the number I put in! Any help will be appreciated.