java大轉(zhuǎn)盤抽獎(jiǎng)代碼 java實(shí)現(xiàn)大轉(zhuǎn)盤抽獎(jiǎng)

公司年會(huì)要進(jìn)行抽獎(jiǎng)活動(dòng)java代碼實(shí)現(xiàn)

參考

10年的十堰鄖陽網(wǎng)站建設(shè)經(jīng)驗(yàn),針對(duì)設(shè)計(jì)、前端、開發(fā)、售后、文案、推廣等六對(duì)一服務(wù),響應(yīng)快,48小時(shí)及時(shí)工作處理。全網(wǎng)營(yíng)銷推廣的優(yōu)勢(shì)是能夠根據(jù)用戶設(shè)備顯示端的尺寸不同,自動(dòng)調(diào)整十堰鄖陽建站的顯示方式,使網(wǎng)站能夠適用不同顯示終端,在瀏覽器中調(diào)整網(wǎng)站的寬度,無論在任何一種瀏覽器上瀏覽網(wǎng)站,都能展現(xiàn)優(yōu)雅布局與設(shè)計(jì),從而大程度地提升瀏覽體驗(yàn)。創(chuàng)新互聯(lián)從事“十堰鄖陽網(wǎng)站設(shè)計(jì)”,“十堰鄖陽網(wǎng)站推廣”以來,每個(gè)客戶項(xiàng)目都認(rèn)真落實(shí)執(zhí)行。

int custNO;//客戶會(huì)員號(hào)(說明:customer指客戶)

System.out.println ("請(qǐng)輸入四位會(huì)員卡號(hào):");//輸入會(huì)員卡號(hào)

Scanner input = new Scanner(System.in);

custNO = input.nextInt();

if (custNo 1000){

//獲得每位數(shù)字(a/b是除a%b是取余)

int gewei = custNO % 10 ; //分解獲得個(gè)位數(shù) 1001 %10 ==1

int shiwei = custNO /10 %10 ; //分解獲得十位數(shù) //1234 /10 % 10 = 123 %10 =3 (1234 /10 = 123.4 % 10 )

int baiwei = custNO /100 %10 ;//分解獲得百位數(shù)

int qianwei = custNO /1000 ; //分解獲得千位數(shù)

}

//計(jì)算數(shù)字之和

int sum = gewei + shiwei + baiwei + qianwei ;

System.out.println ("會(huì)員卡號(hào)"+custNO +"各位之和:" + sum );

Java代碼實(shí)現(xiàn)抽獎(jiǎng):從班級(jí)的學(xué)號(hào)中抽出一個(gè)一等獎(jiǎng),兩個(gè)二等獎(jiǎng),三個(gè)三等獎(jiǎng)

抽取問題, 重點(diǎn)是 同一個(gè)學(xué)號(hào)不能重復(fù)被抽取.

解決辦法很多,

比如數(shù)組可以使用下標(biāo)來標(biāo)記,號(hào)碼是否被使用,使用了就繼續(xù)下一次抽取

也可以使用集合來抽取,把集合順序打亂,然后隨便抽幾個(gè)就可以了

參考代碼:數(shù)組法

import?java.util.Random;

public?class?Test?{

public?static?void?main(String[]?args)?{

int?stuNums=30;

int[]?nums=new?int[stuNums];//存儲(chǔ)學(xué)號(hào)的數(shù)組

boolean[]?flags=new?boolean[stuNums];//標(biāo)記,用于標(biāo)記對(duì)應(yīng)下標(biāo)的學(xué)號(hào)是否已經(jīng)被抽取過了

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

nums[i]=i+1;//給學(xué)號(hào)賦值

}

Random?r=new?Random();

while(true){

int?index?=?r.nextInt(stuNums);

if(!flags[index]){

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

flags[index]=true;?//標(biāo)記已經(jīng)被使用過了

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--;//如果已經(jīng)被抽取過了?,那么i建議,再次循環(huán)

}

}

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));

}

}

能不能幫我寫一個(gè)模擬抽獎(jiǎng)機(jī)的JAVA代碼 1到32的八個(gè)數(shù)字

代碼如下:

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

public class Luck extends JFrame implements ActionListener{

JTextField tf = new JTextField();

JButton b1 = new JButton("開始");

JButton b2 = new JButton("停止");

boolean isGo = false;

public Luck(){

b1.setActionCommand("start");

JPanel p = new JPanel();

p.add(b1);

p.add(b2);

b1.addActionListener(this);

b2.addActionListener(this);

b2.setEnabled(false);

this.getContentPane().add(tf,"North");

this.getContentPane().add(p,"South");

this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

this.setSize(300,200);

this.setLocation(300,300);

Cursor cu = new Cursor(Cursor.HAND_CURSOR);

this.setCursor(cu);

this.setVisible(true);

tf.setText("welcome you! ");

this.go();

}

public void go(){

while(true){

if(isGo == true){

String s = "";

for(int j = 1; j = 8;j++){

int i = (int)(Math.random() * 31) + 1;

if(i 10){

s = s + " 0" + i;

}else{

s = s + " " + i;

}

}

tf.setText(s);

}

try{

Thread.sleep(10);

}catch(java.lang.InterruptedException e){

e.printStackTrace();

}

}

}

public void actionPerformed(ActionEvent e){

String s = e.getActionCommand();

if(s.equals("start")){

isGo = true;

b1.setEnabled(false);

b2.setEnabled(true);

}else{

isGo = false;

b2.setEnabled(false);

b1.setEnabled(true);

}

}

public static void main(String[] args){

new Luck();

}

}

看下是你的要求不。若有疑問Hi我。

分享題目:java大轉(zhuǎn)盤抽獎(jiǎng)代碼 java實(shí)現(xiàn)大轉(zhuǎn)盤抽獎(jiǎng)
標(biāo)題URL:http://muchs.cn/article42/ddehihc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供用戶體驗(yàn)、網(wǎng)站營(yíng)銷ChatGPT、定制網(wǎng)站網(wǎng)站排名、關(guān)鍵詞優(yōu)化

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

成都做網(wǎng)站