wap to generate one time password otp?
import java.util.Random;
public class OtpGenerate
{
public static char[] otp(int len)
{
System.out.println("Generating OTP using Random class : ");
System.out.print("Your OTP Number is : ");
String num="0123456789";
Random r1=new Random();
char [] otp=new char[len];
for(int i=0;i<len;i++)
{
otp[i]=num.charAt(r1.nextInt(num.length()));
}
return otp;
}
public static void main(String[] args) {
System.out.println(OtpGenerate.otp(4));
}
}
import java.util.Random;
public class OtpGenerate
{
public static char[] otp(int len)
{
System.out.println("Generating OTP using Random class : ");
System.out.print("Your OTP Number is : ");
String num="0123456789";
Random r1=new Random();
char [] otp=new char[len];
for(int i=0;i<len;i++)
{
otp[i]=num.charAt(r1.nextInt(num.length()));
}
return otp;
}
public static void main(String[] args) {
System.out.println(OtpGenerate.otp(4));
}
}
o/p:-
Generating OTP using Random class :
Your OTP Number is : 3599
No comments:
Post a Comment