1. 程式人生 > >JAVA之氣泡排序—實現雙色球機選小程式

JAVA之氣泡排序—實現雙色球機選小程式

紅球6位:1~33 中不重複的遞增陣列 ,籃球1位:1~16   廢話不多說,上程式碼

pojo

package pojo;


public class Lottery {
public int red;
public int blue;
public int startRed(){
double r = Math.random();
/**產生1-33的隨機數**/
return (int) ((r*33)+1);
}

public int startBlue(){
double r = Math.random();
/**產生1-16的隨機數**/
int blue = (int)(r*16)+1;
return blue;
}
}


__________________________________________________________________________________________________________________________________________

TwoColorBall

package test1;


import java.util.Arrays;
import java.util.Scanner;


import pojo.Lottery;


public class TwoColorBall {


public static void main(String[] args) {
System.out.println("__歡迎來到Switch福利彩票__");
Lottery lot = new Lottery();
System.out.println("");
System.out.println("請輸入你要幾組雙色球,需要是大於0的整數");
Scanner scan = new Scanner(System.in);

int n = scan.nextInt();
if(n>0 && n%1==0){
System.out.println("開始機選搖號!");
   for(int i=0;i<n;i++){

System.out.println("");
System.out.println("第"+(i+1)+"組");

int a[] ={0,1,2,3,4,5};
int complete[] = new int[a.length+1];
boolean flag =true;
while(flag){
for(int j=0;j<6;j++){
a[j] = lot.startRed();
}

for(int s=0;s<6;s++){
for(int k=s+1;k<6;k++){
if(a[s]!=a[k]){

}else{
flag=false;
}
}
}

if(flag==true){
for(int p=0;p<6;p++){
complete[p] = a[p];
}
int temp = 0;
for(int u=0;u<5;u++){
for(int o=0;o<5-u;o++){
if(complete[o]>complete[o+1]){
temp=complete[o];
complete[o]=complete[o+1];
complete[o+1]=temp;
}
}
}
complete[a.length] = lot.startBlue();
System.out.println(Arrays.toString(complete));
flag=false;
}else{
flag=true;
}

}
  }
}else{
System.out.println("您在Switch彩票輸入的機選組數不符合規範,請檢查後輸入!");
}
int everyMoney = 2;
System.out.println("您一共購買了"+n+"組彩票,請支付"+(n*everyMoney)+"元!");
}
}

最後原諒我命名一個這麼low的名字,文化低......