Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Importing the Random library
- import java.util.Random;
- class LuckyFive {
- public static void main(String[] args) {
- // Creating a random number generator
- Random randomGenerator = new Random();
- // Generate a number between 1 and 6
- int dieRoll = randomGenerator.nextInt(6) + 1; //+1 so that this will not include 0 but the highest no. itself 6
- //without +1 -- will generate number from 0 to 5
- // Repeat while roll isn't 5
- while (dieRoll !=5){
- System.out.println(dieRoll);
- dieRoll = randomGenerator.nextInt(6) + 1;
- /*this while loop will generate a different set of numbers each time of different length
- because until it generates the number 5 then it will stop & exit the loop
- */
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement