「抽奖活动java」抽奖活动方案策划

博主:adminadmin 2022-12-18 16:06:10 59

本篇文章给大家谈谈抽奖活动java,以及抽奖活动方案策划对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。

本文目录一览:

java抽奖程序

我给你个比较简单的,,但是需要按照你的要求进行稍微的修改。。然后在main方法中去执行就可以了:

public class GoodLuck {

int custNo;

int i=1;

String answer;

String awardName;

public void LuckNo(){

Scanner input=new Scanner(System.in);

System.out.println("\n我行我素购物管理系统 幸运抽奖\n");

do{

// 需要的话请把随机数调整成你想要的范围(我这个是为了测试方便写的1

(~3的随机数,根据你的需要把下面的3换成你想要的数字就行了)

int num=(int)(Math.random()*3+1);

System.out.print("请输入会员卡号(4位整数):");

custNo=input.nextInt();

//百位数与随机数相同的为幸运者

int bai=custNo/100%10;

while(i==1){

if(custNo=1000custNo=9999){

break;

}

else{

System.out.println("\n会员号码输入有误,请重新输入:");

custNo=input.nextInt();

continue;

}

}

if(bai==num){

showAward();

System.out.print("\n卡号:"+custNo+"是幸运客户,获得"+awardName);

}else{

System.out.print("\n卡号:"+custNo+"\t谢谢您的支持!");

}

System.out.println("\n是否继续(y/n)");

answer=input.next();

while(i==1){

if(answer.equals("y")||answer.equals("n")){

break;

}else{

System.out.print("输入有误!请重新输入:");

answer=input.next();

continue;

}

}

}while(!answer.equals("n"));

}

public void showAward(){

int num=(int)(Math.random()*3+1);

if(num==1){

awardName="Mp3";

}

else if(num==2){

awardName="美的微波炉";

}

else{

awardName="美的电饭锅";

}

}

Java代码实现抽奖:从班级的学号中抽出一个一等奖,两个二等奖,三个三等奖

抽取问题, 重点是 同一个学号不能重复被抽取.

解决办法很多,

比如数组可以使用下标来标记,号码是否被使用,使用了就继续下一次抽取

也可以使用集合来抽取,把集合顺序打乱,然后随便抽几个就可以了

参考代码:数组法

import java.util.Random;

public class Test {

public static void main(String[] args) {

int stuNums=30;

int[] nums=new int[stuNums];//存储学号的数组

boolean[] flags=new boolean[stuNums];//标记,用于标记对应下标的学号是否已经被抽取过了

for (int i = 0; i  stuNums; i++) {

nums[i]=i+1;//给学号赋值

}

Random r=new Random();

while(true){

int index = r.nextInt(stuNums);

if(!flags[index]){

System.out.println("A等:"+nums[index]);

flags[index]=true; //标记已经被使用过了

break;

}

}

for (int i = 0; i  2; i++) {

int index = r.nextInt(stuNums);

if(!flags[index]){

System.out.println("B等:"+nums[index]);

flags[index]=true;

}else{

i--;//如果已经被抽取过了 ,那么i建议,再次循环

}

}

for (int i = 0; i  3; i++) {

int index = r.nextInt(stuNums);

if(!flags[index]){

System.out.println("c等:"+nums[index]);

flags[index]=true;

}else{

i--;

}

}

}

}

集合法

import java.util.ArrayList;

import java.util.Collections;

public class Test2 {

public static void main(String[] args) {

int stuNums=20;

ArrayListInteger list=new ArrayListInteger();

for (int i = 0; i  stuNums; i++) {

list.add(i+1);

}

System.out.println("有序"+list);

Collections.shuffle(list);//打乱顺序

System.out.println("乱序"+list);

System.out.println("A等"+list.get(0));

System.out.println("B等"+list.get(1));

System.out.println("B等"+list.get(2));

System.out.println("C等"+list.get(3));

System.out.println("C等"+list.get(4));

System.out.println("C等"+list.get(5));

}

}

抽奖Java程序(是作业,急需

本来老早都给你弄好了,可你也不操心,一直没有给你发;现在就这样,需要改的话,说一下

/**

* 根据倒叙的字符串,获取与最后一位相同的位数

* @param string -倒叙后的字符串

* @return -后几位相同

*/

public static int getString( String string){

String string1 = string+"-";

//正则

String[] arr1 = string1.split(string1.toCharArray()[0]+"");

String string2 = string1.substring(0,arr1.length-1)+"-";

String[] arr2 = string2.split(string2.toCharArray()[0]+"");

return arr1.length==arr2.length?arr1.length-1:

getString(string.substring(0,arr1.length-1))

;

}

/**

* 后几位相同

* @param num

* @return

*/

public static int get(Integer num,Integer o){

String string = (num+o)+"";

StringBuffer buffer = new StringBuffer(string);

string = buffer.reverse().toString();//字符串倒叙

int count = getString(string);

return count==3o==0?3:

count==4o==0?2:

count==6o==0?1:

count==3o==1?31:

count==4o==1?21:

count==6o==1?11:

count==3o==-1?32:

count==4o==-1?22:

count==6o==-1?12: -1;

}

public static void main(String[] args) {

MapString,String map = new TreeMap();

SetInteger set = new HashSet();

set.add(402223);

set.add(402221);

set.add(401223);

set.add(401221);

set.add(222223);

set.add(222221);

int b = 0,n=30;

while (true){

int random = (int) (Math.random()*(1000000-100000) + 100000);

set.add(random);

if (set.size() == n){

break;

}

}

for (Integer key:set){

int count = get(key,0);

//最后一个数字是0或9的话就只有一个

count = count 0key%10!=9?get(key,1):count;

count = count 0key%10!=1?get(key,-1):count;

String str = count0?(

count/10==0?(

count==3?"third":count==2?"second":"first"

)

:(

"adjacent"

)

):

"blank";

//"欢迎再来";

map.put("买到的号码:"+key, str);

}

System.out.println(map);

}

求一份抽奖游戏(Java写的代码)

import java.util.Scanner;

/**

 *

 */

public class f {

    public static void main(String args[]){

        Scanner scan = new Scanner(System.in);

        System.out.print("请输入抽奖号码上限:");

        int max = scan.nextInt();

        System.out.print("请输入抽奖次数:");

        int n = scan.nextInt();

        System.out.print("中奖号码依次为:");

        for(int i=0;in;i++){

            System.out.print((int)(Math.random()*max+1)+" ");

        }

    }

}

商场推出幸运抽奖活动的java初级代码编写

public class Lucky {

public static void main(String[] args){

System.out.println("请输入您的4位会员卡号:");

Scanner sc = new Scanner(System.in);

int number = sc.nextInt(); //接收用户从控制台输入的会员卡号,并保存在会员卡号变量中

int a = number/1000; //千位

int b = number%1000/100; //百位

int c = number%100/10; //十位

int d = number%10; //个位

if((a+b+c+d)20){

System.out.println("恭喜中奖!您是幸运客户");

}else{

System.out.println("谢谢参与!");

}

}

}

最基础的 没有异常判断 无限循环输入什么东西

关于抽奖活动java和抽奖活动方案策划的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。

The End

发布于:2022-12-18,除非注明,否则均为首码项目网原创文章,转载请注明出处。