introductionToProgramming/week3/RollLoadedDie.java
2025-09-22 15:51:40 +02:00

10 lines
394 B
Java

public class RollLoadedDie {
public static void main(String[] args) {
double rand8 = Math.random() * 8.;
// floor returns double. Round gives long for double input, so conversion needed
int random = (int)(Math.round(Math.floor(rand8)) + 1);
// 1 - 8 to 1 - 6, with 6 receiving the probabilities of 7 - 8
random = Math.min(random, 6);
System.out.println(random);
}
}