導航:首頁 > 源碼編譯 > 彩票java演算法

彩票java演算法

發布時間:2023-03-19 13:57:37

1. 用java便攜一個程序,用來模擬隨機生成一個36選7的彩票號碼

就是孫談從判指36個數中選出7個,這36個數是什麼可以自己指定,但必須保證不重復,我寫的一個代碼則沖碰
public
class
test
{
public
static
void
main(String[]
args)
{
int[]
a
=
new
int[36];
for(int
i
=
0;
i
<
36;
++i)
a[i]
=
i+1;
for(int
i
=
0;
i
<
5;
++i)
randomSelect(a,
7);
}
static
void
randomSelect(int[]
a,
int
n)
{
randomShuffle(a,
7);
for(int
i
=
0;
i
<
n;
++i)
System.out.print(a[i]
+
"
");
System.out.println();
}
static
void
randomShuffle(int[]
a,
int
n)
{
for(int
i
=
0;
i
<
n;
++i)
{
int
r
=
(int)(Math.random()
*
a.length);
int
tmp
=
a[i];
a[i]
=
a[r];
a[r]
=
tmp;
}
}
}

2. 3D彩票JAVA編程怎麼寫

importjava.util.ArrayList;importjava.util.List;importjava.util.Random;importjava.util.Scanner;publicclassLotto{publicstaticfinalintNUMBER=7;publicstaticvoidmain(String[]args){List<Integer>userNumbers=newArrayList<Integer>();Scannerscanner=newScanner(System.in);inti=1;while(i<8){System.out.println("輸入第"+i+"個數字:");userNumbers.add(scanner.nextInt());i++;}System.out.println(prize(userNumbers.toArray(newInteger[NUMBER])));}privatestaticInteger[]generateLotto(){List<Integer>lottoNumbers=newArrayList<Integer>();Randomrand=newRandom();intlottoNumber,i=0;while(i<NUMBER){lottoNumber=rand.nextInt(35)+1;if(!lottoNumbers.contains(lottoNumber)){lottoNumbers.add(lottoNumber);i++;}}returnbubbleSort(lottoNumbers.toArray(newInteger[NUMBER]));}privatestaticInteger[]bubbleSort(Integer[]array){for(inti=0;i<array.length;i++){for(intj=0;j<array.length-i-1;j++){if(array[j]>array[j+1]){inttemp=array[j+1];array[j+1]=array[j];array[j]=temp;}}}returnarray;}publicstaticStringprize(Integer[]userNumbers){intcount=0;Integer[]lottoNumbers=generateLotto();for(Integeri:userNumbers){for(Integerj:lottoNumbers){if(i==j){count++;}}}return"猜對了"+count+"個彩票號碼";}}
輸入第1個數字:
5
輸入第2個數字:
14
輸入第3個數字:
19
輸入第4個數字:
24
輸入第5個數字:
33
輸入第6個數字:
34
輸入第7個數字:
27
猜對了3個彩票號碼

3. java的彩票

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

/**
* 測試彩票類
* @author doulmi
*
*/
爛卜液public class LotteryDemo {
public static void main( String[] args ) {
Scanner scanner = new Scanner( System.in );
System.out.print( "請輸入要購買的注數:" );
System.out.println();

int buyN = 0;
if ( scanner.hasNextInt() ) {
buyN = scanner.nextInt();
} else {
System.out.println( "請輸入正確的數字" );
}

弊答for ( int i = 0; i < buyN; i ++ ) {
Lottery lot = new Lottery();
lot.generate();
System.out.print( "第" );
System.out.print( i );
System.out.print( "注" );
lot.printData();
}
}
}

飢物/**
* 彩票類
* @author Administrator
*
*/
class Lottery {
private static final int NUM_TO_GETOUT = 7;
//能產生的最大數值為99
private static final int MAX_NUM = 35;
public ArrayList< Integer > list;
private int[] result;

public Lottery() {
list = new ArrayList< Integer >();
for ( int i = 1; i <= MAX_NUM; i ++ ) {
list.add( i );
}
result = new int[ NUM_TO_GETOUT ];
}

public void generate() {
Random r = new Random();
for ( int i = 0; i < NUM_TO_GETOUT; i ++ ) {
result[ i ] = list.remove( r.nextInt( list.size() ) );
}
}

/**
* 關於票頭的列印。。我不知道票頭是什麼。
*/
public void pringTitle() {

}

/**
* 實現號碼的列印
*/
public void printData() {
for ( int n : result ) {
System.out.print( n );
System.out.print( " " );
}
System.out.println();
}
}

4. 用JAVA寫一個3D彩票游戲,給我一個用JAVA寫的游戲代碼。簡單。

package communitys.Connect;
import java.util.Random;

public class telephs {

public static void main(String[] args) {

D3D d3d1 = new D3D(1,1000);
D3D d3d2 = new D3D(2,2000);
D3D d3d3 = new D3D(3,3000);

Thread th1 = new Thread(d3d1);
Thread th2 = new Thread(d3d2);
Thread th3 = new Thread(d3d3);

th3.start();
th2.start();
th1.start();

}
}class D3D implements Runnable
{ private int sum;
private int g ;
public D3D(int g ,int sum)
{
this.sum = sum;
this.g = g;
}

public void run() {

try {
Thread.sleep(sum);
System.out.println("3D的開獎結果--第"+g+"個數是:"+go());
} catch (InterruptedException e) {

e.printStackTrace();
}
}

public int go()
{
Random ra = new Random();

return ra.nextInt(9);
}

}
結果

5. java一個彩票演算法的問題

邏輯沒問題??? 題目都感覺有點那啥....
下一次至少要買多少注保證中獎後不會虧本。這句話里這個「至少」。。。不應該是「最多」???而且,買彩票這種事。要是能這樣簡單的算出來,那別人都不要玩了。

6. 彩票系統需要什麼java技術

主要是演算法,彩票系統很復雜,我大二做了一個,用java寫的,獲得了江蘇省軟體創新一等獎,其實主要是演算法!

7. 用Java程序寫一個彩票的模擬程序生成6個紅球(1-33的隨機數),1個藍球(1-16的隨機數),隨機數可以重復

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

public class DoubleBalls {

public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("是否機選一組雙色球號碼?(Y/N)");
Scanner input = new Scanner(System.in);
char a = input.next().charAt(0); // 輸入一個char字元,0位即是第一位

if (a == 'Y' || a == 'y') {
Random suiji = new Random(); // 創建suiji方法
int blue = suiji.nextInt(16);//從0到16中選一個數字個藍球
while(blue==0){
blue=suiji.nextInt(16);
}//如果選到了0,再選一次給blue
int red[] = new int[6];// 用一個6個元素的數組裝紅球
for (int i = 0; i < 6; i++) {
red[i] = suiji.nextInt(33); // 隨機分配0到33的整數
if (red[i] == 0) {i--;}
if (i == -1) {i = 0;}
for (int j = 0; j < i; j++) {
while (red[i] == red[j]) {i--;}// 發現相同的從新回去生成一個
}
}
System.out.print("紅球:");
for (int k = 0; k < red.length; k++) {
System.out.print(red[k] + " ");// 輸出數組red
}
System.out.print("藍球:"+blue);
} else
System.out.println("fuck you~");
}
}

應該可以了,可以產生一組。。。如果樓主你中頭獎了,送我套房好了哈^0^

閱讀全文

與彩票java演算法相關的資料

熱點內容
成都市土地出讓金演算法 瀏覽:697
鋼筋加密標記 瀏覽:567
ps中擴展功能在文件夾的什麼位置 瀏覽:903
雙極壓縮機為什麼要先高壓 瀏覽:527
蘋果手機伺服器填什麼 瀏覽:832
android移動動畫效果 瀏覽:691
電子和伺服器是什麼意思 瀏覽:691
phpurl中文亂碼問題 瀏覽:893
程序員那麼可愛大結局陸漓產子 瀏覽:538
java如何從雲伺服器讀取本地文件 瀏覽:923
壓縮空氣軟管製作方法 瀏覽:911
天河三號演算法 瀏覽:924
php隊列教程 瀏覽:632
洪水命令 瀏覽:529
安卓怎麼弄成蘋果在線 瀏覽:435
谷歌web伺服器地址 瀏覽:898
安卓鎖屏圖片如何刪除 瀏覽:719
python3多進程編程 瀏覽:714
證明代碼是程序員寫的 瀏覽:397
演算法錯誤發現辦法 瀏覽:410