Java--彩票案例

package ssq;

import java.util.Arrays;
import java.util.Random;
import java.util.Scanner;
public class text {

    public static void main(String[] args) {


        int[] redball = new int[6];
        int blueball = 0;
        Random ran = new Random();
        for (int i = 0; i < redball.length - 1; i++) {
            int index = ran.nextInt(33) + 1;
            redball[i] = index;
            for (int j = 0; j < i; j++) {
                if (redball[i] == redball[j]) {
                    i--;
                }
            }
        }
        redball[5] = ran.nextInt(16) + 1;
        Arrays.sort(redball, 0, 6);
        String str = Arrays.toString(redball);
        Random go = new Random();
        int index1 = go.nextInt(16) + 1;
        blueball = index1;
        System.out.println("开奖号码为:" + str + blueball);
        System.out.println("输入六位红色号码:");
        int[] userBall = new int[6];
        Scanner red = new Scanner(System.in);
        for (int i = 0; i < redball.length; i++) {
            userBall[i] = red.nextInt();
        }
        System.out.println("输入一位蓝色号码");
        int userBall1 = 0;
        Scanner blue = new Scanner(System.in);
        userBall1 = blue.nextInt();
        int rednumber = 0;
        int bluenumber = 0;
        for (int i = 0; i < redball.length; i++) {
            for (int j = 0; j < userBall.length; j++) {
                if (redball[i] == userBall[j]) {
                    rednumber++;
                }
            }

        }
        if (userBall1 == blueball) {
            bluenumber++;
        }
        if (rednumber == 6 && bluenumber == 1) {
            System.out.println("恭喜你,中一等奖500万");

        } else if (rednumber == 6 && bluenumber == 0) {
            System.out.println("恭喜你,中二等奖100万");

        } else if (rednumber == 5 && bluenumber == 1 || rednumber == 5 && bluenumber == 0) {
            System.out.println("恭喜你,中三等奖3000元");

        } else if (rednumber == 4 && bluenumber == 1 || rednumber == 4 && bluenumber == 0) {
            System.out.println("恭喜你,中四等奖200元");

        } else if (rednumber < 4 && bluenumber == 1) {
            System.out.println("恭喜你,中五等奖5元");

        } else {
            System.out.println("感想你为公益事业做出贡献");
        }


    }


}



评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值