Loading

java抢红包控制台小游戏

package com.lu;

import java.util.Random;
import java.util.Scanner;

public class Text6 {//抢红包

    public static void main(String[] args) {
        double[] arr = {9,9999,6,8,88};
        grabTheRedEnvelope(arr);
    }
    public static void grabTheRedEnvelope(double[] arr){
        Scanner input = new Scanner(System.in);
        Random r = new Random();
        for (int i = 0; i < arr.length; i++) {
            System.out.println("请输入任何符号抽奖");
            input.next();
            int a = r.nextInt(5);
            while (true){
                if (arr[a]==0){
                    a = r.nextInt(5);
                    continue;
                }
                break;
            }

            System.out.println("恭喜你抽中红包"+arr[a]+"元!");
            arr[a]=0;


        }

    }
}

posted @ 2024-10-10 09:57  LL。。。  阅读(16)  评论(0)    收藏  举报  来源