Java to write a four-digit random verification code

Source: Internet
Author: User

Import java.util.random;/* Random number class: Write a function to randomly generate a four-bit verification code. */public class Demo5 {public static void main (string[] args) {/*random random = new random (); int randomnum = Random.nextin T (10) +1; The resulting random number is between 0-10 System.out.println ("Random number:" + randomnum); */char[] arr = {' In ', ' country ', ' pass ', ' a ', ' Q ', ' f ', ' B '}; StringBuilder sb = new StringBuilder (); Random random = new random ();//requires four random numbers to get the characters in the character array by random number, for (int i = 0; i< 4; i++) {int index = Random.nextint (Arr.leng  TH); The resulting random number must be within the range of the index value of the array. Sb.append (Arr[index]);} System.out.println ("Verification Code:" + SB);}}


Java writes a four-digit random verification code

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.