转: [转]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