掷骰子是 Java 中流行的程序,
public class Die {
/* This program simulates rolling a die */
public static void main(String[] args) {
int die; // The number on the die.
die = (int)(Math.random()*6 + 1);
System.out.println (die);
} // end main()
} // end class
我想做的是让它重复 500 次。我没能把这个程序放入一个 500 的循环中。我通常用 Python 编程,所以我猜我的 Java 已经生锈了!
欢迎任何帮助!
最佳答案
您可以为此使用for
语句。在 this Sun tutorial 了解更多信息.
例如
for (int i = 0; i < 500; i++) {
// This will be executed 500 times.
}
关于java - 在 Java 中掷骰子,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2612170/