javaSE部分7.11整理

四舍五入  %.2f  String.fromat()
String.format("%.3f", 3.1415926);
		System.out.println(result);

随机数

	double rdm=Math.random();   //[0,1)的随机数————double
	System.out.println(rdm);
        Random random = new Random();
	random.nextInt(int bound);---->包头不包尾 例:random.nextInt(11)--->[0,10)   

        实例:做一个四位验证码

           Random random = new Random();
		StringBuffer sb = new StringBuffer();
		for(int i=0;i<4;i++){
			sb.append(random.nextInt(10));
		}
		System.out.println(sb);


 
 


猜你喜欢

转载自blog.csdn.net/qq_42667028/article/details/80998856
今日推荐