工具类生成验证码:
工具类:
package Java_project_1;
import java.util.Random;
public class Account {
private Account(){
}
public static String createVerifyCode(int n){
String code="";
String data = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
Random r=new Random();
for (int i=0;i<n;i++){
int index= r.nextInt(data.length());
code+=data.charAt(index);
}
return code;
}
}
主类:
package Java_project_1;
import java.util.ArrayList;
import java.util.Random;
import java.util.Scanner;
public class Java_project_1 {
public static void main(String[] args) {
System.out.println(Account.createVerifyCode(6));
}
}
定义数组工具类:
工具类:
package Java_project_1;
public class ArrayUtil {
private ArrayUtil(){
}
public static String toString(int[] arr){
if(arr==null){
return null;
}
String result="[";
for (int i=0;i< arr.length;++i){
result+=(i== arr.length-1?arr[i]:arr[i]+",");
}
result+="]";
return result;
}
}
主类:
package Java_project_1;
import java.util.ArrayList;
import java.util.Random;
import java.util.Scanner;
public class Java_project_1 {
public static void main(String[] args) {
int[] arr=null;
int[] arr1={};
int[] arr2={12,23,55,66};
System.out.println(ArrayUtil.toString(arr));
System.out.println(ArrayUtil.toString(arr1));
System.out.println(ArrayUtil.toString(arr2));
}
}