package org.mobiletrain;
import java.util.Scanner;
public class Test01 {
private static void bubbleSort(int [] array) {
boolean swapped = true;
for(int i = 1; swapped && i < array.length; i++) {
swapped = false;
for (int j = 0; j < array.length - i; j++) {
if (array[j] > array[j + 1]) {
int temp = array[j];
array[j] = array[j + 1];
array[j + 1] = temp;
swapped = true;
}
}
}
}
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("机选几注:");
int n = input.nextInt();
input.close();
for(int counter = 1; counter <= n;counter++) {
int[] redBalls = new int[6];
for (int i = 0; i < redBalls.length;) {
//生成1~33的随机数,作为红色球的号码
int number = (int) (Math.random() * 33 + 1);
//检查此号码在之前选中的号码中有没有出现过
boolean isDuplicated = false;
for (int j = 0; j < i; j++) {
//如果当前号码已经出现过
if (redBalls[j] == number) {
isDuplicated = true;
break;
}
}
if (!isDuplicated) {
redBalls[i] = number;
i++;//只有选中不重复的,i才+1.
}
}
bubbleSort(redBalls);
for(int x: redBalls){
System.out.printf("%02d ", x);
}
int blueBall = (int) (Math.random() * 16 + 1);
System.out.printf("(%02d)\n",blueBall);//%02d表示,数字不够两位,前面补0
}
}
}
双色球选号程序(非面向对象)
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
推荐阅读更多精彩内容
- 程序 = 数据结构 + 算法 面向对象就是:将一类事物的特点归纳出来,属性=数据结构,行为=算法。然后用类(cla...
- settimeout(function(){},0) 问题:如上函数,原本settimeout的作用是等待第二个参...
- 卓普科技今天和大家聊一聊美团,这个在电商O2O模式大逆风环境下,仍然凭借O2O保持高速、高调、高发展的一家综合服务...