1.设计一个验证码,前四位为任意字母组合,最后一位为数字。
package com.itheima.demo1;
import java.util.Random;
public class method {
public static void main(String[] args) {
String s = "";
for (int i = 1; i <= 5; i++) {
if (i<=4){
s = s+free();}
else {
s = s + nfree();
}
}
System.out.println(s);
}
public static char free () {
Random r = new Random();
int num = r.nextInt(26);
return (char) ('a' + num);
}
public static char nfree() {
Random r = new Random();
int s = r.nextInt(10);
return (char) ('0' + s);
}
}