public class CaipiaoOne {
public static void main(String[] args) throws Exception {
int n = 0
int[] num = new int[7]
System.out.print("请输入要生成的注数:")
BufferedReader in = new BufferedReader(new InputStreamReader(System.in))
n = Integer.parseInt(in.readLine())
int tmp = 0
for(int i=0i<ni++){
for(int j=0j<7j++){
tmp=(int)(Math.random()*36)
while(tmp==0)
tmp=(int)(Math.random()*36)
System.out.print(tmp+" ")
}
System.out.println()
}
}
}
//Lottery类
import java.util.Date
class Lottery{
int[] num = new int[7]//用于存放随机产生的7个号码
//实现7个号码的产生
public void generate(){
int tmp
for(int j=0j<7j++){
tmp=(int)(Math.random()*36)
while(tmp==0)
tmp=(int)(Math.random()*36)
num[j]=tmp
}
}
//实现票头的打印
public static void pringTitle(){
System.out.println("欢迎使用本彩票号码选择器")
System.out.println("********************")
System.out.println(new Date())
System.out.println()
}
//实现号码的打印
public void printData(){
for(int j=0j<7j++){
System.out.print(num[j]+" ")
}
System.out.println()
}
public Lottery(){
generate()
printData()
}
}
//测试类
import java.io.*
public class CaipiaoTwo {
public static void main(String[] args) throws Exception {
System.out.print("请输入要生成的注数:")
BufferedReader in = new BufferedReader(new InputStreamReader(System.in))
int n = Integer.parseInt(in.readLine())
Lottery.pringTitle()
for(int i=0i<ni++){
new Lottery()
}
}
}
import java.util.ArrayListimport java.util.Collections
import java.util.List
import java.util.Random
public class Main {
public static void main(String[] args) {
//红球 33 选6
List<Integer> redBall = new ArrayList<Integer>()
for(int i=0i<33i++){
redBall.add(i+1)
}
System.out.println("开奖红球:" + select(redBall, 6))
//篮球16选1
List<Integer> blueBall = new ArrayList<Integer>()
for(int i=0i<16i++){
blueBall.add(i+1)
}
System.out.println("开奖蓝球:" + select(blueBall, 1))
}
public static List<Integer> select(List<Integer> list,int count){
List<Integer> selectedList = new ArrayList<Integer>()
Random random = new Random()
for(int i=0i<counti++){
int index = random.nextInt(list.size())
Integer number = list.get(index)
selectedList.add(number)
list.remove(index)
}
Collections.sort(selectedList)
return selectedList
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)