转: [转]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
int radomInt = new Random().nextInt(999999); int radomInt2 =(int)((Math.random()*9+1)*100000); System.out.println(radomInt); System.out.println(radomInt2);
int radomInt = new Random().nextInt(999999) @org.junit.Test public void testName() throws Exception { Random random = new Random(); float radomInt = random.nextInt(999); System.out.println(radomInt == 0 ? "000" : (radomInt<100 ? String.valueO
package rbq.codedemo; import java.util.regex.Pattern; /** * Created by rbq on 2016/12/13. */ public class NumUtils { public static boolean isNum(String str){ Pattern pattern = Pattern.compile("^-?[0-9]+"); if(pattern.matcher(str).matches()){ //数