日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

java项目001.双色球游戏

發(fā)布時間:2023/12/10 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java项目001.双色球游戏 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

package Suangseq;

//雙色球游戲制作。

import java.awt.SystemColor;

import java.util.Arrays;

import java.util.Scanner;

public class TextA {

?????? public static void main(String[] args) {

?????????????

????????????? boolean flag=false;//定義一個布爾類型的變量。

????????????? int[] my=null;//定義一個變量

????????????? int num=0;

?????????????

????????????? while (true) {

????????????????????

???????????????????? System.out.println("*****歡迎進入雙色球系統(tǒng)*****");

???????????????????? System.out.println("\t1.購買彩票");

???????????????????? System.out.println("\t2.查看開獎");

???????????????????? System.out.println("\t3.退出系統(tǒng)");

???????????????????? System.out.println("***************************");

????????????????????

???????????????????? System.out.println("請選擇菜單:");

???????????????????? Scanner scanner=new Scanner(System.in);

???????????????????? int menu=scanner.nextInt();

????????????????????

???????????????????? switch (menu) {

???????????????????? case 1:

//????????????????????????? System.out.println("購買彩票");

??????????????????????????? System.out.println("你需要下多少注?");

??????????????????????????? num=scanner.nextInt();//num中保存用戶下注多少

???????????????????????????

??????????????????????????? my=userBuy();//接收用戶輸入信息的返回值。

????????????????????????????????????????????????

??????????????????????????? System.out.println("你一共買了【"+num+"】注,共需要支付【"+(num*2)+"】元,所選號碼為:"+Arrays.toString(my));

???????????????????????????

??????????????????????????? flag=true;//如果購買成功,就把flag賦值為true

??????????????????????????? break;

???????????????????? case 2:

???????????????????????????

??????????????????????????? if (flag) {//證明已經(jīng)購買了彩票

??????????????????????????????????

//???????????????????????????????? System.out.println("查看開獎");

??????????????????????????????????

?????????????????????????????????? int[] sys=sysNum();//獲得系統(tǒng)產(chǎn)生的隨機數(shù)號碼

??????????????????????????????????

?????????????????????????????????? System.out.println("系統(tǒng)產(chǎn)生的:"+Arrays.toString(sys));

?????????????????????????????????? System.out.println("自己輸入的:"+Arrays.toString(my));

??????????????????????????????????

?????????????????????????????????? compareA(sys, my,num);

?????????????????????????????????? flag=false;//進行開獎結(jié)束后需要把flag重新的賦值為false,否則可以無限開獎

??????????????????????????????????

??????????????????????????? }else {

?????????????????????????????????? System.out.println("請先購買彩票!!!");

??????????????????????????? }

????????????????????

??????????????????????????? break;

???????????????????? case 3:

??????????????????????????? System.out.println("謝謝使用該系統(tǒng),請離開");

???????????????????????????

??????????????????????????? //直接關(guān)閉控制臺,退出系統(tǒng)

//????????????????????????? System.exit(status:0);

??????????????????????????? return;

????????????? ?????? default:

??????????????????????????? System.out.println("請輸入正確的菜單編號!");

???????????????????? }

????????????? }

?????? }

??????

??????

?????? //用戶輸入的內(nèi)容和系統(tǒng)隨機產(chǎn)生的內(nèi)容進行比較

?????? public static void compareA(int[] sys,int[]my,int num) {

????????????? int redCount=0;

????????????? int blueCount=0;

????????????? //兩個數(shù)組進行對比

????????????? //紅球數(shù)量的對比

????????????? for (int i = 0; i < sys.length-1; i++) {

???????????????????? for (int j = 0; j < sys.length; j++) {

??????????????????????????? if (sys[i]==my[j]) {

?????????????????????????????????? redCount++;

??????????????????????????? }

???????????????????????????

???????????????????? }

????????????????????

????????????? }

?????????????

????????????? //籃球內(nèi)容對比

????????????? if (sys[6]==my[6]) {

???????????????????? blueCount++;

????????????? }

?????????????

????????????? System.out.println("紅球相同個數(shù):"+redCount+",籃球相同個數(shù):"+blueCount);

????????????? //根據(jù)紅球,籃球個數(shù)進行結(jié)果比較。???????????

????????????? if (redCount==6&&blueCount==1) {

???????????????????? System.out.println("恭喜你中獎:"+(1000*num)+"萬");

????????????? } else if(redCount==6){

???????????????????? System.out.println("恭喜你中獎:"+(500*num)+"萬");

????????????? }else if(redCount==5&&blueCount==1){

???????????????????? System.out.println("恭喜你中獎:"+(3000*num));

????????????? }else if(redCount==5||(redCount==4&&blueCount==1)){

???????????????????? System.out.println("恭喜你中獎:"+(200*num));

????????????? }else if(redCount==4||(redCount==3&&blueCount==1)){

???????????????????? System.out.println("恭喜你中獎:"+(10*num));

????????????? }else if(blueCount==1){

???????????????????? System.out.println("恭喜你中獎:"+(5*num));

????????????? }else {

???????????????????? System.out.println("倒霉鬼沒有中獎!!!");

????????????? }

?????????????

?????? }

??????

//用戶購買的方法

?????? public static int[] userBuy(){

?????????????

????????????? Scanner scanner=new Scanner(System.in);

??????

????????????? int[] my=new int[7];//用于保存自己輸入的號碼

?????????????

????????????? //用戶輸入的6個紅球

????????????? for (int i = 0; i < 6; i++) {

????????????????????

???????????????????? System.out.println("請輸入6個紅球號碼(數(shù)字是:1-33),第"+(i+1)+"個紅球為:");

???????????????????? int red = scanner.nextInt();//用戶輸入每一個紅球數(shù)字

???????????????????? //將輸入的紅球存到數(shù)組

???????????????????? if (red<=33&&red>=1) {

??????????????????????????? my[i]=red;

???????????????????????????

???????????????????? }else{

??????????????????????????? System.out.println("請輸入正確號碼!!!");

??????????????????????????? i--;//用戶輸入錯誤i,一定減掉,保持輸入紅球次數(shù)為6

???????????????????? }

????????????? }

????????????????????

?????????????

????????????? while (true) {

???????????????????? //用戶單獨輸入一個籃球

???????????????????? System.out.println("請輸入一個籃球號碼(數(shù)字為1-16):");

???????????????????? int blue=scanner.nextInt();

???????????????????? //把用戶輸入的值保存到數(shù)組最后一個位置

????????????????????

???????????????????? if (blue>=1&&blue<=16) {

??????????????????????????? my[6]=blue;

??????????????????????????? break;

???????????????????? }

??????

????????????? }

???????????????????? return my;

?????? }

??????

???? //把系統(tǒng)隨機產(chǎn)生的號碼,依次保存到int數(shù)組中

?????? public static int[] sysNum() {

?????????????

?????? //系統(tǒng)隨機產(chǎn)生7位數(shù)字(前6位是1-33,最后一位是1-16)

?????? int[] sys=new int[7];

??????

?????? for (int i = 0; i < 6; i++) {

????????????? int ran=(int)(Math.random()*33)+1;//每次產(chǎn)生一個隨機數(shù)

????????????? sys[i]=ran;

?????? }

?????? //最后一位隨機數(shù)字

?????? sys[6]=(int)(Math.random()*16)+1;

?????? return sys;

??????

?????? }

}

?

總結(jié)

以上是生活随笔為你收集整理的java项目001.双色球游戏的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。