Generate an activation code using the random number generation method, such as 12hj-9hjf-hhty-kk8g

Source: Internet
Author: User

Generate an Activation code

Package jihuoma;//generates activation code: similar to 2hs0-sskj-9hho-a55dpublic class Test {public static void main (string[] args) {String str= ""; for (int i = 1; i <=; i++) {int a= (int) (Math.random ()),//0,1,2,[0,3) take an integer between if (a==0) {str=str+ (char) ((int) ( Math.random () * (' Z '-' a ' + 1)) + ' A ');} if (a==1) {str=str+ (char) ((int) (Math.random () * (' Z '-' a ' + 1)) + ' A ');} if (a==2) {str=str+ (char) ((int) (Math.random () * (' 9 '-' 0 ' + 1)) + ' 0 ');} if (i%4==0&&i<16)//each 4 plus one-representative separation, equal to 16 o'clock does not have to add. {str=str+ '-';}} System.out.println (str);//print output randomly generated activation code}}


Generate 10 Activation codes (more than one layer of loops outside)

Package jihuoma;//generates 10 activation codes public class Test2 {public static void main (string[] args) {for (int j = 0; J < x + +) {//follow Ring 10 times, generate 10 Activation code string str= ""; for (int i = 1; i <=; i++) {//16 times after the loop generates an activation code int a= (int) (Math.random ());//0,1,2if (a==0) {str=str+ (char) ((int) (Math.random () * (' Z '-' a ' + 1)) + ' A ');} if (a==1) {str=str+ (char) ((int) (Math.random () * (' Z '-' a ' + 1)) + ' A ');} if (a==2) {str=str+ (char) ((int) (Math.random () * (' 9 '-' 0 ' + 1)) + ' 0 ');} if (i%4==0&&i<16) {str=str+ '-';}} System.out.println (str);}}}


Generate an activation code using the random number generation method, such as 12hj-9hjf-hhty-kk8g

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.