❮ Previous Next ❯

JAVA : How to generate OTP

Hi frnds, here I am going to represent to generate random OTP. only core java file.
Required Files:

  1. OTPExample.java

Example of generate random OTP

In this example, we are using only coreJAVA.
OTPExample.java


 package java8s;

 import java.util.*;

 public class OtpExample
   {

     static char[] show(int len)
       {
         System.out.print("Your OTP is : ");

         String numbers = "0123456789";

         Random rd = new Random();

         char[] otp = new char[len];

         for (int i = 0; i < len; i++)
           {

             otp[i] =
             numbers.charAt(rd.nextInt(numbers.length()));
           }
           return otp;
       }

         public static void main(String[] args)
           {

             int length = 5;
             System.out.println(show(length));

           }

 }


OUTPUT


Your OTP is : 35838





❮ Previous Next ❯

Follow Us




  Tutorials

Popular Links

Contact Us

address Plot No-741,2ND Floor
Opp. Bhagabati Temple,Jayadev Vihar
      Bhubaneswar-751013
      Email: info@silantechnology.com
      Phone: 0674-2361252
address
39877, sundale dr, apt#101, Fremont, California 94538, USA
       Phone: +1(262)388-7619

facebook twitter google linked in

© 2018 Silan Technology. All Rights Reserved