首页 > 编程语言 >程序清单3_7

程序清单3_7

时间:2023-02-05 17:47:52浏览次数:31  
标签:int System result println 程序清单 numbers out

package java_hexin;

import java.util.Arrays;
import java.util.Scanner;

public class j3_7 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);

        System.out.println("How many numbers do you need to draw?");
        int k = in.nextInt();

        System.out.println("What is the highest numbers you can draw?");
        int n = in.nextInt();

        // 抽奖数字
        int[] numbers = new int[n];
        for (int i = 0; i < numbers.length; i++) {
            numbers[i] = i + 1;
        }

        //
        int[] result = new int[k];
        for (int i = 0; i < result.length; i++) {
            int r = (int) (Math.random() * n);

            result[i] = numbers[r];

            numbers[r] = numbers[n - 1];
            n--;
        }
        Arrays.sort(result);
        System.out.println("Bet the following combination.It'll make you rich!");
        for (int r : result) {
            System.out.println(r);
        }
    }
}

标签:int,System,result,println,程序清单,numbers,out
From: https://www.cnblogs.com/arciab/p/17093681.html

相关文章

  • 程序清单3_9
    packagejava_hexin;publicclassj3_9{publicstaticvoidmain(String[]args){finalintNMAX=10;int[][]odds=newint[NMAX+1][];......