|
![](static/image/common/ico_lz.png)
楼主 |
发表于 2006-7-6 22:04
|
显示全部楼层
坐思又想还是觉得22楼那个太傻了,弄的那么复杂,出了几个错误,到现在错误还没有排除,就算排除了,估计也不好用,弄的太麻烦了,这么晕,会死人的.所以决定不在小panel上做文章了,还是以大panel里每个zeile或者每个reihe随机出几个数,只要不重复,就好,这样看着也简单,实际操作起来也方便.
弄了半天在Math.random上出问题了,原来这个random用过的啊,应该没有问题才对,以前还做过个练习,lotto随机出数的程序,现在看看,以前编的程序都有错误了,怎么回事啊.贴上来请高手看看
- class Lotto {
- Lotto () {
- boolean [] gezogen = new boolean[49];
- int neuezahl,
- anzahl = 0;
- for (int i = 0;i < 49;i++) gezogen[i] = false;
- while (anzahl != 6) {
- neuezahl = (int)(Math.random() * 49);
- if (!gezogen[neuezahl]) {
- gezogen[neuezahl] = true;
- anzahl++;
- }
- }
- for (int i = 0;i < 49;i++)
- if (gezogen[i]) System.out.println(i + 1);
- }
- public static void main (String [] args){
- new Lotto ();
- }
- }
复制代码
还有,greenflute说出随机数还有别的,我查了查,dokumentation里有,但是有命令,没有实例,我弄不太清楚啊,具体怎么用?比如:Random();protected int next(int bits);还有public int nextInt(int n);都怎么用啊,高手们,能不能给个简单的例子啊? 谢谢拉 |
|