- import java.util.Scanner;
- /*
- * 需求:设计一个方法,可以获取任意返回任意范围的随机数
- *
- */
- public class MathDemo {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- System.out.println("请输入范围的起始值:");
- int start = sc.nextInt();
- System.out.println("请输入范围的结束值:");
- int end = sc.nextInt();
-
- for (int x = 0; x < 100; x++) {
- int number = getRandom(start, end);
- System.out.println(number);
- }
- }
- public static int getRandom(int start, int end) {
- int number = (int) (Math.random() * (end - start + 1))+ start;
- return number;
-
- }
- }
复制代码
|
|