package com.day14; public class Demo01 { public static char[] demo01(){ String i = "1234567890"; //String r ="1"; String word=i; char[] c=word.toCharArray(); return c; } }
package com.day14; import java.util.Random; public class Demo02 { public static void main(String[] args) { for (int i = 0; i < 20; i++) { String s = 1+verifyCode();//手机号开头为1 System.out.println(s); } } public static String verifyCode(){ char[] c=Demo01.demo01();//获取数字的字符数组 Random rd = new Random(); String code=""; for (int k = 0; k <= 10; k++) { int index = rd.nextInt(c.length);//随机获取数组长度作为索引 code+=c[index];//循环添加到字符串后面 } return code; } }