双色球开奖编程:
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);
}
}
© 著作权归作者所有
发表评论