通过Math.random函数生成所需的字符所有序列,通过判断当前字符是否属于大小写.数字,符合者加入数组内,直到数组存储N位为止,最后把当前数组转为字符串返回调用处. /** * 随机生成由数字.字母组成的N位验证码 * * @return 返回一个字符串 */ public static String getCode(int n) { char arr[] = new char[n]; int i = 0; while (i < n) { char ch = (char) (int) (Ma
SQL code select char(cast(rand()*25 as int)+97)+char(cast(rand()*25 as int)+97) select 两位随机字母 = (select top 1 id from (select 'A' as id union select 'B' union select 'C' union select 'D' union select 'E' union select 'Z') m order by newid
转: [转]Java生成三位随机数 public class Test2 { public static void main(String [] srgs) { int i=(int)(Math.random()*900)+100; //int i= new java.util.Random().nextInt(900)+100;也可以System.out.println(i); } } 也就是要求100到999之间的随机数, Math.random()返回的是0到1之间的随机数,返回类型为do
java保留两位小数问题: 方式一: 四舍五入 double f = 111231.5585; BigDecimal b = new BigDecimal(f); double f1 = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); 保留两位小数 --------------------------------------------------------------- 方