package homework;
import java.util.*;
/**
* 随机产生四位验证码 0--9,a--z,A--Z随机取4个数作为验证码
提示 a-z 范围65-90
A-z 范围97-122
* @author 雨
*
*/
public class Homework2 {
public static void main(String[] args){
ArrayList<Object> array=new ArrayList<Object>();
Random rand =new Random();
for(int i=0;i<4;i++){
int choice=rand.nextInt(3);
switch (choice) {
case 0:
int num=rand.nextInt(9);
array.add(num);
break;
case 1:
int num2=rand.nextInt(25)+65;
char low=(char)num2;
array.add(low);
break;
case 2:
int num3=rand.nextInt(25)+97;
char high=(char)num3;
array.add(high);
break;
default:
break;
}
}
System.out.println("你得到的四位验证码:");
for (Object object : array) {
System.out.print(object);
}
}
import java.util.*;
/**
* 随机产生四位验证码 0--9,a--z,A--Z随机取4个数作为验证码
提示 a-z 范围65-90
A-z 范围97-122
* @author 雨
*
*/
public class Homework2 {
public static void main(String[] args){
ArrayList<Object> array=new ArrayList<Object>();
Random rand =new Random();
for(int i=0;i<4;i++){
int choice=rand.nextInt(3);
switch (choice) {
case 0:
int num=rand.nextInt(9);
array.add(num);
break;
case 1:
int num2=rand.nextInt(25)+65;
char low=(char)num2;
array.add(low);
break;
case 2:
int num3=rand.nextInt(25)+97;
char high=(char)num3;
array.add(high);
break;
default:
break;
}
}
System.out.println("你得到的四位验证码:");
for (Object object : array) {
System.out.print(object);
}
}
}