免费视频淫片aa毛片_日韩高清在线亚洲专区vr_日韩大片免费观看视频播放_亚洲欧美国产精品完整版

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開通VIP
雙色球案例
這篇源代碼優(yōu)點(diǎn)小問題:有時(shí)間再調(diào)試
package zaizhu.da;

import java.util.Arrays;//數(shù)組類
import java.util.Scanner;//輸入類
import java.util.Random;//隨機(jī)數(shù)類

public class Test35 {
public static void main(String[] args) {
        int[] userRedBall=new int[6];//用戶紅球
        int userBlueBall=0;//用戶藍(lán)球
        
        int[] sysRedBall=new int[6];//系統(tǒng)紅球 
        int sysBlueBall=0;//系統(tǒng)藍(lán)球
        
        int redCount=0;//記錄紅球
        int blueCount=0;//記錄籃球
        
        int[] redBall=new int[33];//存儲(chǔ)紅球
        //需要隨機(jī)生成 1---33不重復(fù)的6 個(gè)數(shù)
        for(int i=0;i<redBall.length;i++) {
        redBall[i]=i+1; 
        }
        
        //游戲開始
        System.out.println("游戲開始!");
        System.out.println("請(qǐng)問你是機(jī)選還是手選?1.機(jī)選 2手選");
        Scanner input=new Scanner(System.in);
        Random r=new Random();
        boolean flag=true;
        while(flag) {
        int isAuto=input.nextInt();
        switch(isAuto) {//1 機(jī)選 2手選
        case 1:
        computerSelection(redBall,userRedBall);//機(jī)選紅球
        userBlueBall=r.nextInt(17);//機(jī)選籃球
        flag=false;//退出循環(huán)
        break;
        case 2:
        System.out.println("請(qǐng)選擇6個(gè)號(hào)碼:(1--33)");
        for(int i=0;i<userRedBall.length;i++) {
        userRedBall[i]=input.nextInt();
        }
        System.out.println("請(qǐng)選擇一個(gè)籃球:(1--16)");
        userBlueBall=input.nextInt();
    flag=false;
        break;
        }
        }      
        //系統(tǒng)隨機(jī)生成號(hào)碼:
        //紅球
        computerSelection(redBall,sysRedBall);
        //籃球
        sysBlueBall=r.nextInt(16)+1;
        //統(tǒng)計(jì)結(jié)果:
        //紅球:
        for(int i=0;i<userRedBall.length;i++) {
        for(int j=0;j<sysRedBall.length;j++) {
        if(userRedBall[i]==sysRedBall[j]) {
        int temp=sysRedBall[j];
        sysRedBall[j]=sysRedBall[sysRedBall.length-1-redCount];
        sysRedBall[sysRedBall.length-1-redCount]=temp;
        redCount++;
        break;
        }
        }
}
        //籃球:
        if(userBlueBall==sysBlueBall) {
        blueCount=1;
        }
        //驗(yàn)證是否中獎(jiǎng)
        if(blueCount==0&&redCount==0) {
        System.out.println("革命尚未成功,同志任需努力!");
        }else if(blueCount==1&&redCount<=3){
        System.out.println("恭喜你!中了六等獎(jiǎng)!5元");
        }else if((blueCount==1&&redCount==3)&&(blueCount==0&&redCount==4)) {
        System.out.println("恭喜你!中了五等獎(jiǎng)!10元");
        }else if((blueCount==1&&redCount==4)&&(blueCount==0&&redCount==5)) {
        System.out.println("恭喜你!中了四等獎(jiǎng)!200元");
        }else if((blueCount==1&&redCount==5)&&(blueCount==0&&redCount==6)) {
        System.out.println("恭喜你!中了三等獎(jiǎng)!3000元");
        }else if(blueCount==0&&redCount==6) {
        System.out.println("恭喜你!中了二等獎(jiǎng)!20W朝上!");
        }else if(blueCount==1&&redCount==6) {
        System.out.println("恭喜你!中了一等獎(jiǎng)!900W附近!");
        }else {
        System.out.println("系統(tǒng)輸出有誤!");
        }
        //公布系統(tǒng)號(hào)碼:
        System.out.println("本期中獎(jiǎng)號(hào)碼:");
        sort1(sysRedBall);
        System.out.println("Arrays.toString(sysRedBall)");
        System.out.println("Arrays.toString(sysBlueBall)");
        
        //公布用戶號(hào)碼:
        System.out.println("你的號(hào)碼:");
        sort1(userRedBall);
        System.out.println("Arrays.toString(userRedBall)");
        System.out.println("Arrays.toString(userBlueBall)");
        
}
    //冒泡排序
    public static void sort1(int[] ball) {
    for(int i=0;i<ball.length;i++) {
    for(int j=0;j<ball.length-1-i;j++) {
    if(ball[j]>=ball[j+1]) {
    ball[j]=ball[j]+ball[j+1];
    ball[j+1]=ball[j]-ball[j+1];
    ball[j]=ball[j]-ball[j+1];
    }
    }
    }
    }
    
    
//指定數(shù)列中隨機(jī)生成不重復(fù)數(shù)列                       //1--33             //6個(gè)數(shù)
public static void computerSelection(int[] redBall,int[] userRedBall) {
Random r=new Random();
int index=-1;
for(int i=0;i<userRedBall.length;i++) {//循環(huán)六次
index=r.nextInt(redBall.length-i);
userRedBall[i]=redBall[index];
 
int temp=redBall[index];
redBall[index]=redBall[redBall.length-i-1];
redBall[redBall.length-i-1]=temp;
}
}
}

分享知識(shí),分享快樂!希望中國(guó)站在編程之巔!

               ----

本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
第四講:方法與數(shù)組
Java編程入門:模擬雙色球
java 選擇排序
(三)數(shù)組的復(fù)制
隨機(jī)驗(yàn)證碼(二)
(Java)尋找最大值
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長(zhǎng)圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服