1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| import java.util.Random;
public class NumUtil {
public static int createNum(int len) { Random random = new Random(); int max = (int) (Math.pow(10, len) - Math.pow(10, len - 1)); return random.nextInt(max) + (int) Math.pow(10, len - 1); }
public static void main(String[] args) { for (int i = 1; i < 50; i++) { int num = createNum(4); System.out.println("num1 = " + num); } } }
|