import java
.util
.Arrays
;
import java
.util
.Scanner
;
public class Demo {
public static void main(String
[] args
) {
Scanner sc
= new Scanner(System
.in
);
System
.out
.println("总共能抽几次?");
int k
= sc
.nextInt();
System
.out
.println("能抽到的最大数字是:");
int n
= sc
.nextInt();
int [] nums
= new int[n
];
for (int i
= 0; i
< nums
.length
; i
++) {
nums
[i
] = i
+ 1;
}
int [] result
= new int[k
];
for (int i
= 0; i
< result
.length
; i
++) {
int r
= (int) (Math
.random() * n
);
result
[i
] = nums
[r
];
nums
[r
] = nums
[n
- 1];
n
--;
}
Arrays
.sort(result
);
System
.out
.print("抽到的数字按升序排列为:");
for(int r
: result
) {
System
.out
.print(r
+ " ");
}
System
.out
.println("");
System
.out
.println(Arrays
.toString(result
));
}
}
转载请注明原文地址:https://tech.qufami.com/read-4269.html