import java.util.Arrays; import java.util.Random; import java.util.Scanner; public class test3 { public static void main(String[] args) { Random random = new Random(); char [] arr =new char[52]; for (int i = 0; i <= arr.length-27; i++) { arr[i]=(char)(65+i); arr[i+26]=(char)(97+i); } System.out.println(Arrays.toString(arr)); int []arr1=new int[10]; for (int i = 0; i < 10; i++) { arr1[i]=i; } System.out.println(Arrays.toString(arr1)); String [] arr2= new String[5]; for (int i = 0; i < 4; i++) { arr2[i]= String.valueOf(arr[random.nextInt(0,51)]); } arr2[4]= String.valueOf((arr1[random.nextInt(0,9)])); System.out.println("验证码:"+Arrays.toString(arr2)); System.out.println("验证码:"+Arrays.toString(arr2)); System.out.println("验证码:"+Arrays.toString(arr2)); System.out.println("请输入验证码:"); Scanner scanner = new Scanner(System.in); String [] arr3= new String[5]; for (int i = 0; i < arr3.length; i++) { arr3[i]=scanner.next(); } if (arr2.equals(arr3)){ System.out.println("输入正确"); }else System.out.println("输入错误"); } }
这是自己做的验证码,每次验证的时候总是出错,有没有大神懂得,帮我看看;
最新推荐文章于 2024-11-11 21:19:25 发布