首页 > 学院 > 开发设计 > 正文

随机生成8位数

2019-11-06 08:04:30
字体:
来源:转载
供稿:网友
import java.util.Random;public class RandomTest {    public static void main(String[] args) {        StringBuilder str=new StringBuilder();//定义变长字符串        Random random=new Random();        //随机生成数字,并添加到字符串        for(int i=0;i<8;i++){            str.append(random.nextInt(10));        }        //将字符串转换为数字并输出        int num=Integer.parseInt(str.toString());        System.out.PRintln(num);    }}
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表