Java Random(随机函数)

426 阅读1分钟
// 导库
import java.util.Random;

public class test {
  public static void main(String[] args) {
    // 创建对象
    Random r = new Random();
    // 获取随机数,随机范围 0-10, 包括0,不包括10
    int x = r.nextInt(10);
    // 输出数据
    System.out.println(x);
  }  
}