// 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;
// Repeat while roll isn't 5
while (dieRoll != 5) {
System.out.println(dieRoll);
dieRoll =5;
}
}
}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter