玩法规则:“双色球”每注投注号码由 6 个红色球号码和 1 个蓝色球号码
组成。红色球号码从 1—33 中选择,蓝色球号码从 1—16 中选择。
package section_6_1008;import java.util.Random;
import java.util.Scanner;public class section_6_1008 {public static void main(String[] args) {// TODO Auto-generated method stubint [] redBall = new int[6] ;// 红色球int blueBall = 0 ;// 蓝色球System.out.println("请输入你的红球") ;//输入用户号码Scanner input = new Scanner (System.in) ;for(int a = 0 ; a < redBall.length; a++){redBall [a] = input.nextInt() ;}System.out.println("请输入你的蓝球") ;Scanner input1 = new Scanner (System.in) ;blueBall = input1.nextInt() ;int[] red = new int[6]; // 摇奖红色球int blue ; // 摇奖蓝色球Random random = new Random();//随机数for (int i = 0 ; i < red.length; i++) {// random.nextInt(int)red[i] = random.nextInt(32) + 1;//调用nextInt(32)会生成一个0-32之间的数,+1消去0}blue = random.nextInt(15) + 1;/*int [] redBall = {1 , 5 , 6 , 4 , 9 , 8 } ;//测试int [] red = {1 , 5 , 6 , 4 , 9 , 8 } ;int blueBall = 0;int blue = 2;*/int redSameTime = 1 ;for(int c = 0 ; c < redBall.length -1 ; c++ )//判断是否中奖{for(int d = 0 ; d < red.length - 1; d++ ){if(redBall [c] == red [d]){redSameTime ++ ;}}}System.out.println(redSameTime) ;if(blueBall == blue)//公布结果{if(redSameTime == 6){System.out.println("恭喜你中了一等奖") ;}else if(redSameTime == 5){System.out.println("恭喜你中了3等奖") ;}else if(redSameTime == 4){System.out.println("恭喜你中4了等奖") ;}else if(redSameTime == 3){System.out.println("恭喜你中了5等奖") ;}else if(redSameTime == 2 || redSameTime == 1 || redSameTime == 0){System.out.println("恭喜你中了6等奖") ;}else {System.out.println("很遗憾你没有中奖") ;}}else {if(redSameTime == 6){System.out.println("恭喜你中了二等奖") ;}else if(redSameTime == 5){System.out.println("恭喜你中了4等奖") ;}else if(redSameTime == 4){System.out.println("恭喜你中5了等奖") ;}else{System.out.println("很遗憾你没有中奖") ;}}// 输出开奖情况for (int i = 0; i < red.length ; i++) {System.out.print(red[i] + "\t") ;}System.out.print("蓝球");System.out.println("\t" + blue) ;System.out.println("你的红球是") ;for(int b = 0 ; b < redBall.length ; b++){System.out.print(redBall [b]+ "\t") ; }System.out.print("蓝球\t") ;System.out.print(blueBall) ;}}