在爪哇扔骰子
掷骰子是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已经生锈了
欢迎任何帮助
# 1 楼答案
忘记如何做循环有点奇怪,但以下是我的解决方案:
请注意,我使用了Random。nextInt()而不是数学。随机()。这有几个原因
希望有帮助:)
# 2 楼答案