双色球开奖

双色球开奖编程:
import java.util.Random;
public class TwoColorBall {
public static void main(String[] args) {
Random ran = new Random();
int blue = ran.nextInt(16) + 1;
int[] red = new int[6];//定义6个元素数组
for (int i = 0; i < red.length; i++) {//循环赋值
int num = ran.nextInt(33) + 1;//随机数值
for (int j = 0; j < red.length; j++) {
if (num == red[j]) {//如果给的数值和前边赋值相等
i--;//不生效,i减一,下次继续赋值
break;//和前面相比,只要遇到相等就可以跳出
}
}
red[i] = num;
}
System.out.println("本期开奖号码: ");
for (int i = 0; i < red.length; i++) {
System.out.print(red[i] + " ");
}
System.out.println(blue);
}

}

Image placeholder
还差得远呢!
未设置
  0人点赞

没有讨论,发表一下自己的看法吧

推荐文章