很多时候在论坛注册的时候总是有这样的验证
a+b=?
这样的验证方法是很简单的,以下java代码就是类似于此类验证
1 package com.duduli.li.db;
2
3 import java.util.Random;
4 import java.util.Scanner;
5
6 public class CheckCodeNumAdd {
7 private int num3 = 0;
8
9 public void nextWord(){
10 Random rd = new Random();
11 int num1 = rd.nextInt(20);
12 int num2 = rd.nextInt(20);
13 num3 = num1 + num2;
14 System.out.println(num1 + "+" + num2 + "= ?");
15 // System.out.println(num3);
16 }
17
18 public static void main(String[] args) {
19 // TODO Auto-generated method stub
20 CheckCodeNumAdd mt = new CheckCodeNumAdd();
21 Scanner scan = new Scanner(System.in);
22 int num = 0;
23 mt.nextWord();
24 num = scan.nextInt();
25 if(num == mt.num3){
26 System.out.println("successful");
27 }else{
28 System.out.println("failure");
29 }
30 }
31 }
32