2.26
package random; //随机输入一个11位数的电话号码 //第一位是1 第二位是不小于3的数字 import java.util.Random; public class RandomNum { public static void main(String[] args) { Random rand = new Random(); System.err.println("随机生成的九个11位的电话号码是:"); for(int i = 0;i<11;i++) { do { int num = rand.nextInt(2); if(num == 1) { System.out.print(num); break; } }while(true); do { int num = rand.nextInt(10); if(num >= 3) { System.out.print(num); break; } }while(true); for(int j = 0;j<9;j++) { int num = rand.nextInt(10); System.out.print(num); } System.out.println(); } } }
package random; import java.util.Random; import javax.swing.text.AbstractDocument.Content; //随机生成6位验证码 public class RandomYzm { public static void main(String[] args) { Random ran = new Random(); System.out.print("随机的6位验证码是:"); for(int j = 0;j<6;j++) { do { int num = ran.nextInt(150); if(num>64&&num<91) { char ch = (char)num; System.out.print(ch); break; } if(num>96&&num<123) { char ch = (char)num; System.out.print(ch); break; } if(num<10) { System.out.print(num); break; } }while(true); } }
}