描述
模拟王者荣耀抽奖,通过不同的卡牌类型数量来控制不同等级的奖品概率
输入数据
用户选择单抽还是10连抽
输出结果
每次抽奖结果及账户余额
package com.demo;
import java.util.Random;
import java.util.Scanner;
public class RaffleSystem {
public static void main(String[] args) {
//创建卡牌库
String [] card={"B:小乔","B:大乔","S:吕布","A:赵云","A:张飞","A:周瑜"
,"B:大乔","B:关羽","A:许褚","A:张郃","B:刘备","B:关羽","B:黄忠",
"B:颜良","A:张辽", "S:曹操", "B:刘备","B:小乔","B:黄忠","B:马岱"};
//产生随机数
Random rd=new Random();
//初始化随机账户金额
int count=rd.nextInt(2000)+1880;
//随机数初始化
int num=0;
//创建扫描器
Scanner sc=new Scanner(System.in);
//循环抽奖
while(count>=188){
//选择抽奖方式
System.out.println("请选择单抽还是连抽:\n1.单抽\t2.10连抽");
//接收输入数字
int numInput=sc.nextInt();
if(numInput==1){
num=rd.nextInt(card.length-1);
System.out.print(card[num]+"\t\n");
count-=188;
System.out.println("您的余额为:"+count);
}else if(numInput==2 ){
if(count>=1880){
for(int i=1;i<=10;i++){
num=rd.nextInt(card.length-1);
System.out.print(card[num]+"\t");
}
System.out.println();
count-=1880;
System.out.println("你的余额为:"+count);
}
else{
System.out.println("您的余额不足,请充值或者选择单抽");
}
}else{
System.out.print("输入的抽奖序号不正确,请重新输入:");
}
}
}
}