模拟36选7(代码)

import java.util.*;
public class Test
{   static boolean luck=false;
    static int mun=0;
private static void kaiJiang(int a1[])//随机产生7个开奖号码
{for(int i=0;i<a1.length;i++)
{a1[i]=(int)(Math.random()*36+1);
     for(int j=i-1;j>=0;j--)
if(a1[i]==a1[j]) {i--;break;}
}
}
private static void duiJiang(int a1[],int a2[],int a3[])//兑奖方法
{for(int i=0;i<a1.length-1;i++)
for(int j=0;j<a2.length-1;j++)
     if(a1[i]==a2[j])  a3[mun++]=a2[j];

if(a1[6]==a2[6]) {luck=true;mun++;}  //特别号码
}
public static void main(String[] args)
{int[] a1=new int[7];
int[] a2=new int[7];
int[] a3=new int[7];
Scanner sc=new Scanner(System.in);
int i,j;
kaiJiang(a1);
     System.out.println("选7个号码:");
for(i=0;i<a2.length;i++)
{a2[i]=sc.nextInt();
}
duiJiang(a1,a2,a3);
System.out.println("开奖结果:");
for(i=0;i<a1.length;i++)
        System.out.print(a1[i]+" ");
System.out.println("\n中奖个数:"+mun+":"+"\n中奖号码:");
for(i=0;i<mun;i++)
        System.out.print(a3[i]+" ");
if(luck) System.out.println("\n特别号码:"+a1[6]+"******中了!");
else System.out.println("\n特别号码:"+a1[6]+"******不中!");
}
}

你可能感兴趣的:(代码)