package com.karl; import java.util.Random; public class RandomDemo { public static void main(String[] args) { //创建一个Random对象,用于生成随机数 Random r=new Random(); //调用Random提供的功能:nextInt得到随机数 for (int i = 1;i <= 20;i++) {//选中代码,然后ctrl+alt+t选择循环(只是增加了循环多执行了几次) int number=r.nextInt(10);//0-9 System.out.println("随机数:"+number); } System.out.println("-----------------------------------"); for (int i=1;i<=20;i++) { int m=r.nextInt(10)+1;//1-10=>(0-9)+1 System.out.println(m); } } }
标签:int,Random,System,nextInt,随机数,public From: https://www.cnblogs.com/Karl-hut/p/17438001.html