1.JAVA课ç¨è®¾è®¡ 彩票å·ç 产çå¨
2.求java程序随机生成**双色球
3.java 福利**32选6 这段代码 能随机选出6个不重复的彩票a彩号码,但是手机 不能排除0;求大神指教,修改!端源刘畊宏源码
4.javaç彩票
JAVA课ç¨è®¾è®¡ 彩票å·ç 产çå¨
æè¿æä¸ªè¶ çº§å¤§ä¹éç代ç å¨æ§å¶å°è¾åºç è¿æ²¡æç»è®¡å¥é¡¹æ¦ç å¸æå¯ä»¥å¸®å°ä½ ï¼1.å 说ä¸æè·¯ a.声æ2个æ°ç»å2个åéæ°ç»åå«æ¾ååºç个æ°åååºç个æ°,码ja免码åéåå«ä¸ºè¿ä¸¤ä¸ªæ°ç»çé¿åº¦ b.é¦å éæºè·å¾ååºç5个å·ç ï¼Random .nextInt(ååºé¿åº¦çåé) è·å¾éæºæ°,æ¾å°ç¬¬ä¸ä¸ªæ°ç»ä¸ä¸æ 为è¿ä¸ªéæºæ°çå ç´ ,ååºæ¾å¨åéä¸. è¿ãããå¿å¯ä»¥å¤ææ ¼å¼ ç.å¯ä»¥ç¨æ£å表达å¼å¤ææ¯å¦ä¸ºåä½æ°,å¦ææ¯çè¯å°±è¡¥å ¨0.ç¶å移é¤æ°ç»ä¸è¿ä¸ªå ç´ .å½ç¶åå¨æ°ç»çåéè¦åå»1çç¶åéå¤ãã以ä¸ç4次è¿æ ·å°±è·å¾äº1-ä¸5个ä¸éå¤çæ°å. c.åä¸. 2.é代ç SuperJoyful.javaimport java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Random;
import java.util.regex.Matcher;
import java.util.regex.Pattern;/
*** 以ä¸æ¯æ¨¡æä¸ä¸ªè¶ 级大ä¹ééæºéå·åè½ï¼ä¸¥æ ¼ææ¦ççæ
* @author Jack
*
*/
public class SuperJoyful {
// 声æä¸ä¸ªListç¨äºåæ¾ååºå·ç
private List<Integer> objFrontList = new ArrayList<Integer>();
// 声æä¸ä¸ªListç¨äºåæ¾ååºå·ç
private List<Integer> objBackList = new ArrayList<Integer>();
// 声æä¸ä¸ªæ£å表达å¼å¯¹è±¡ï¼ç¨äºå¹é æ¯å¦æ¯ä¸ä½æ°å,ç¨äºè¾åºæ¶éªè¯
Pattern objP = Pattern.compile("\\d");
// æè¦æä½çå符串
Matcher objM = null;
String[] Front = new String[5];
String[] Back = new String[2]; // åå§åæå¥å·ç
public void init() {
for (int i = 1; i <= ; i++) {
objFrontList.add(i);
}
for (int i = 1; i <= ; i++) {
objBackList.add(i);
}
} // å¼å§æå¥
public void beginLottery() {
Random objRandom = new Random();
int nFrontCount = ; // ååºå·ç æ»æ°
int nBackCount = ; // ååºå·ç æ»æ° // æå¥åå æ¸ ç©ºLISTï¼ååå§å
objFrontList.clear();
//System.out.println(objFrontList);
objBackList.clear();
//System.out.println(objBackList);
this.init();
/
*** 产ç5个ååºå·ç
*/
for (int i = 0; i < 5; i++) {
//System.out.println("nFrontCount:"+nFrontCount);
// åå§æ¶æ个ååºå·ï¼éæºäº§çä¸ä¸ªç´¢å¼
int nIndex = objRandom.nextInt(nFrontCount);
// å°éåºçå·ç ææ¶åæ¾å¨åéä¸ï¼å¸¦æ£å表达å¼éªè¯
int nTemp = objFrontList.get(nIndex);
String strTemp = new Integer(nTemp).toString();
// å°è·å¾çå·ç ä¸æ£å表达å¼å¹é
objM = objP.matcher(strTemp);
boolean flag = objM.matches();
// å¦ææ¯ä¸ä½æ°ï¼åå¨åé¢è¡¥é¶
if (flag) {
Front[i] = ("0" + strTemp + " ");
} else {
Front[i] = (strTemp + " ");
}
// å é¤LISTä¸è¯¥ç´¢å¼å¤çå·ç ï¼å 为éåºä¸ä¸ªå°±ä¸åæ¾å
objFrontList.remove(nIndex);
// å·ç æ»æ°åå°ä¸ä¸ª
nFrontCount--;
}
Arrays.sort(Front);
for (int n = 0; n < Front.length; n++) {
System.out.print(Front[n] + "\t");
}
System.out.print("+ ");
/
*** 产ç2个ååºå·ç
*/
for (int i = 0; i < 2; i++) {
//System.out.println("nBackCount:"+nBackCount);
// åå§æ¶æ个ååºå·ï¼éæºäº§çä¸ä¸ªç´¢å¼
int nIndex = objRandom.nextInt(nBackCount);
// å°éåºçå·ç ææ¶åæ¾å¨åéä¸ï¼å¸¦æ£å表达å¼éªè¯
int nTemp = objBackList.get(nIndex);
String strTemp = new Integer(nTemp).toString();
// å°è·å¾çå·ç ä¸æ£å表达å¼å¹é
objM = objP.matcher(strTemp);
boolean flag = objM.matches();
// å¦ææ¯ä¸ä½æ°ï¼åå¨åé¢è¡¥é¶
if (flag) {
Back[i] = ("0" + strTemp + " ");
} else {
Back[i] = (strTemp + " ");
}
// å é¤LISTä¸è¯¥ç´¢å¼å¤çå·ç ï¼å 为éåºä¸ä¸ªå°±ä¸åæ¾å
objBackList.remove(nIndex);
// for(int n = 0; n<objBackList.size();n++){
// System.out.println("objBackList:"+objBackList.get( n ));
// }
// å·ç æ»æ°åå°ä¸ä¸ª
nBackCount--;
}
Arrays.sort(Back);
for (int n = 0; n < Back.length; n++) {
System.out.print(Back[n] + "\t");
}
// 产çä¸æ³¨åå车
System.out.println("");
} // æè¦æ±è¾åºå¤å°æ³¨å½©ç¥¨
public void outPutLottery(int vnCount) {
for (int i = 0; i < vnCount; i++) {
this.beginLottery();
}
} /
*** @param args
*/
public static void main(String[] args) {
SuperJoyful objSJ = new SuperJoyful();
EnterConsole objEC = new EnterConsole();
// 声æä¸ä¸ªæ£å表达å¼å¯¹è±¡ï¼ç¨äºå¹é æ¯å¦æ¯æ°å
Pattern objP = Pattern.compile("\\d{ 1,}");
// æè¦æä½çå符串
Matcher objM = null;
// æ¥æ¶æ§å¶å°è¾å ¥
String objTemp = (String) objEC.printConsole();
//String strTemp = (String)objTemp;
objM = objP.matcher(objTemp);
boolean flag = objM.matches();
int nTemp = 0;
if (flag) {
nTemp = new Integer(objTemp);
} else {
System.out.println("对ä¸èµ·ï¼åªè½è¾å ¥æ°åï¼");
}
objSJ.outPutLottery(nTemp);
}
}EnterConsole.javaimport java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class EnterConsole
{
public Object printConsole(){
System.out.print("请è¾å ¥ä½ è¦éæºéåå¤å°æ³¨ï¼ç¡®è®¤å车å³å¯ï¼");
BufferedReader objBR = new BufferedReader(new InputStreamReader(System.in));
String strValue = null;
try
{
strValue = (String)objBR.readLine();
}
catch ( IOException e )
{
// TODO Auto-generated catch block
e.printStackTrace();
}
return strValue;
}
}
求java程序随机生成**双色球
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Random;
public class Main {
static Random r = new Random();
public static void main(String[] args) {
System.out.println("---------W 我来啦----------");
int 注数 = ;
for (int n = 0; n < 注数; n++) {
摇奖();
}
System.out.println("---------W 我来啦----------");
}
public static void 摇奖(){
//红球是1- 篮球是1-
ArrayList<Integer> list1 = new ArrayList<Integer>();
ArrayList<Integer> list2 = new ArrayList<Integer>();
int[] redBalls = new int[6];
for (int j = 0; j < ; j++)
list1.add(j + 1);
for (int i = 0; i < ; i++)
list2.add(i + 1);
// 红球
System.out.print("红球:");
for (int k = 0; k < 6; k++) {
int indexRed = r.nextInt(list1.size());
redBalls[k]=list1.get(indexRed);
list1.remove(indexRed);
}
Arrays.sort(redBalls);//排序后打出红球
for(int s = 0 ; s < redBalls.length ; s++){
System.out.print(getRedBall(redBalls[s]) + " ");
}
int indexBlue = r.nextInt(list2.size());
System.out.println("蓝球:" + getRedBall(list2.get(indexBlue))+"");
}
public static String getRedBall(Integer a){
String b = "";
if (a<) b = "0"+a+"";
else b = a.toString();
return b;
}
}
java 福利**选6 这段代码 能随机选出6个不重复的号码,但是费源文章发布源码下载 不能排除0;求大神指教,修改!彩票a彩asp短信发送源码
按你的手机逻辑,出现0有2种情况:1、端源随机出g==0;可以用 an[i]=g+1; 解决。码ja免码(另外rd.nextInt(n)的费源取值范围是0~n-1)
2、随机出以前相同的彩票a彩数字,但你的手机处理办法是不管了,直接continue,端源php源码 远程下载所以中间就空出一个数字未加到数组an中,码ja免码默认等于0。费源斗地主源码unity可用 i--; 解决
找你的代码稍微改动即可:
for (int i = 0; i < an.length; i++) {g = rd.nextInt(n);
if (bl[g]) {
i--;
continue;
}
an[i] = g+1;
bl[g] = true;
}
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;
ãã//è½äº§ççæ大æ°å¼ä¸º
ããprivate static final int MAX_NUM = ;
ãã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();
ãã}
ãã}