|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
JAVA是一种可以撰写跨平台应用软件的面向对象的程序设计语言,由升阳(SunMicrosystems)公司的詹姆斯·高斯林(JamesGosling)等人于1990年代初开发。程序importjava.util.*;
importjava.io.*;
importjava.lang.*;
publicclassGetLotteryNumber{
publicstaticint[]LotteryNumber=newint[7];
publicstaticinttemp=0;
staticinttemp1=0;
publicstaticvoidmain(String[]args){
if(args.length==0){
System.out.print("彩票号码为:");
OutputLotteryNumber();
}else{
try{
temp1=Integer.parseInt(args[0]);
}catch(Exceptione){
System.out.println("ERROR:"+e.getMessage());
}
if(temp1>99999){temp1=999999;System.out.println("请注重!每次最多只能发生999999组彩票号码。");}
for(inti=0;i<temp1;i++){
System.out.print("第"+(int)(i+1)+"组彩票号码为:");
OutputLotteryNumber();
System.out.println();
}
}
}
publicstaticvoidOutputLotteryNumber(){
LotteryNumberTheard[]Lottery=null;
Randomrandom;
longtempTime;
for(intj=0;j<LotteryNumber.length;j++){
try{
Lottery[j]=newLotteryNumberTheard(j);
random=newRandom(java.lang.System.currentTimeMillis()%197807);
tempTime=random.nextInt((int)(java.lang.System.currentTimeMillis()%793));
Lottery[j].sleep(tempTime);
}catch(Exceptione){
}
}
for(intj=0;j<LotteryNumber.length-1;j++)//排序
for(inti=j+1;i<LotteryNumber.length;i++)
if(LotteryNumber[j]>LotteryNumber[i]){
temp=LotteryNumber[j];
LotteryNumber[j]=LotteryNumber[i];
LotteryNumber[i]=temp;
}
/**
System.out.print("未收拾前的号码:");
for(intj=0;j<LotteryNumber.length;j++)
System.out.print(LotteryNumber[j]+"");
System.out.println();
**/
//扫除反复的数字,并发生新的数字
inter=0;
intflag=0;
while(er<7){
flag=0;
temp=LotteryNumber[er];
for(inti=0;i<LotteryNumber.length-1;i++){
if(temp==LotteryNumber[i]&&er!=i){
temp=CreateLotterNumber();
flag=1;
break;
}
}
if(flag==0){
er+=1;
}else{
LotteryNumber[er]=temp;
}
}
//end
for(intj=0;j<LotteryNumber.length-1;j++)//从头排序
for(inti=j+1;i<LotteryNumber.length;i++)
if(LotteryNumber[j]>LotteryNumber[i]){
temp=LotteryNumber[j];
LotteryNumber[j]=LotteryNumber[i];
LotteryNumber[i]=temp;
}
for(intj=0;j<LotteryNumber.length;j++)
System.out.print(LotteryNumber[j]+" ");
}
publicstaticintCreateLotterNumber(){
inttemp;
Randomrandom1;
random1=newRandom(java.lang.System.currentTimeMillis());
temp=(random1.nextInt())%37;
while(temp==0){
random1=newRandom(java.lang.System.currentTimeMillis());
temp=(random1.nextInt())%37;
}
temp=temp>0?temp:-1*temp;
returntemp;
}
}
classLotteryNumberTheardextendsThread{
GetLotteryNumberGetLottery=newGetLotteryNumber();
Randomrandom;
LotteryNumberTheard(intArraryNumber){
setLotterNumber(ArraryNumber);
}
publicvoidsetLotterNumber(intArrayNumber){
intArNumber=ArrayNumber;
inttemp;
random=newRandom(java.lang.System.currentTimeMillis());
temp=(random.nextInt())%37;
while(temp==0){
random=newRandom(java.lang.System.currentTimeMillis());
temp=(random.nextInt())%37;
}
temp=temp>0?temp:-1*temp;
GetLottery.LotteryNumber[ArNumber]=temp;
}
}
利用:
D:JavaWork>javacGetLotteryNumber.java
D:JavaWork>java-classpath.GetLotteryNumber
彩票号码为:37914263235
D:JavaWork>java-classpath.GetLotteryNumber3
第1组彩票号码为:591013192436
第2组彩票号码为:24615253436
第3组彩票号码为:2142124273031
你对java乐观有点盲目。java的关键就是在服务器上表现优异,而且它提供了整个开发所需要的工具。应该是说,看哪天。net有没有机会赶上java。 |
|