1

我一直在尝试编写一个简单的 java 程序来每次显示随机的字母数字。但是我得到的结果与[C@a3a380

import java.util.*;
import java.security.*;

public class NumericOTPGenerator 
{
    public static void main(String args[])
    {
        int length=5;
        System.out.println("OTP : "+generateOTP(length));
    }
    static char[] generateOTP(int length)
    {
        String capitalChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        String smallChars = "abcdefghijklmnopqrstuvwxyz";
        String numbers = "0123456789";
        String symbols = "!@#$%^&*_=+-/.?<>)";
        String values = capitalChars + smallChars + numbers + symbols;
        char[] generatedOTP = new char[length];
        SecureRandom rand = new SecureRandom();
        for (int i = 0; i < length; i++)
        {
            generatedOTP[i] = values.charAt(rand.nextInt(values.length()));

        }
        return generatedOTP;
    }
}

请建议我如何解决这个问题。

4

0 回答 0