//验证码 前四位是字母 最后一位是数字
public class test1 {
public static void main(String[] args){
char [] chars=new char[52];
for (int i = 0; i <chars.length ; i++) {
if(i<=25){
chars[i]=(char)(i+97);
}
else{
chars[i]=(char)(i+65-26);
}
}
Random r=new Random();
String code="";
for (int i = 0; i <4 ; i++) {
int index=r.nextInt(chars.length);
code+=chars[index];
}
code+=r.nextInt(10);
System.out.println(code);
}
}
技巧
选中 shift+f6 就可以直接修改所有的相同命名的词
抽奖
//抽奖,五个红包,顺序随机不重复,抽五次
public class test1 {
public static void main(String[] args){
int[] array={2,88,8888,99999,30};
int[] newarray=new int[array.length];
Random r=new Random();
for (int i = 0; i <array.length; ) {
int index=r.nextInt(array.length);
boolean flag=exit(newarray,array[index]);
int pri=array[index];
while (!flag){
newarray[i]=pri;
i++;
break;
}
}
for (int i = 0; i <newarray.length ; i++) {
System.out.println(newarray[i]);
}
}
public static boolean exit(int[] newarr,int b){
for (int i = 0; i <newarr.length ; i++) {
if(newarr[i]==b){
return true;
}
}
return false;
}
}