指定范围内生成随机数
随机数生成20~70之间的数值:
public class Random { public static void main(String[] args) { java.util.Random r = new java.util.Random(); for (int i = 0; i < 10; i++) { System.out.print(" " + (r.nextInt(70) + 20)); } } }
运行结果如下图:
随机数生成20~70之间的数值:
public class Random { public static void main(String[] args) { java.util.Random r = new java.util.Random(); for (int i = 0; i < 10; i++) { System.out.print(" " + (r.nextInt(70) + 20)); } } }
运行结果如下图: