关于java的问题,具体程序编写

关于java的问题,具体程序编写,第1张

import java.util.Scannerpublic class test { public static void main( String[] args ) { int[] a = new int[35]for ( int i = 0i <35++i ) { a[i] = i + 1} int nScanner s = new Scanner( System.in )n = s.nextInt()select( a, n )} static void select( int[] a, int n ) { for ( int i = 0i <n++i ) { shuffle( a )System.out.print( "第"+ (i+1) +"注:" )for ( int j = 0j <7++j ) { System.out.print( a[j] + " " )} System.out.println()} } static void shuffle( int[] a ) { int t, tmpfor ( int i = 0i <a.length++i ) { t = (int)(Math.random()*35)tmp = a[t]a[t] = a[i]a[i] = tmp} } }

import java.io.*

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.ArrayList

import 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

}

}


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/8085015.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-13
下一篇 2023-04-13

发表评论

登录后才能评论

评论列表(0条)

保存