我不知道为什么数组的元素为'null'

时间:2018-10-11 17:37:06

标签: java

执行以下程序时,将要求用户输入密码的长度,并在控制台上显示一个随机密码。但是,我不知道为什么所有字符都被打印为“ null”。

package es.pildorasinformaticas.poo;
import java.util.Arrays;
import javax.swing.JOptionPane;

public class Ejercicio55 {
    public static void main(String[] args) {        
        Password mypassword = new Password();       
    }   
}
class Password {
    //Declaring class attributes:
    public int pass_lenght;     
    //Constructor method:
    public Password (){
        pass_lenght = Integer.parseInt(JOptionPane.showInputDialog("¿How many characters do you want the password to be?"));
        String[] array_symbols = {"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","0","1","2","3","4","5","6","7","8","9"};
        String[] array_password = new String[pass_lenght];
        for (String element:array_password) element = array_symbols[(int)Math.random()*62]; 
        for (int i=0;i<pass_lenght;i++) System.out.print(array_password[i]);        
    }
}

谢谢

0 个答案:

没有答案