package im.zyf.javacore;
import java.util.Arrays; import java.util.Scanner;
public class LotteryDrawing {
public static void main(String[] args) {
Scanner in = new Scanner(System.in); System.out.println("how many numbers do you need?"); int k = in.nextInt();
System.out.println("what is the highest number?"); int h = in.nextInt();
int[] harr = new int[h]; for (int i = 0; i < h; i++) { harr[i] = i + 1; }
int[] karr = new int[k]; for (int i = 0; i < k; i++) { int random = (int) (Math.random() * h); karr[i] = harr[random]; harr[random] = harr[h - 1]; h--; } Arrays.sort(karr); System.out.println(Arrays.toString(karr)); } }
|