首页 > 解决方案 > 需要帮助在java中填充数组

问题描述

我需要用 * 和空格填充数组,这就是我到目前为止所拥有的

/*
 *   sets this.phrase array to the passed input
 *   creates this.maskedPhrase array and
 *   fills this.maskedPhrase with * or space characters
 */

public void setGame(char... input)
{

    this.phrase = input;
    this.maskedPhrase = new char[input.length];
    for(int i = 0; i < this.maskedPhrase.length; i++){
        this.maskedPhrase[i] = input[i];
    }            
    System.out.println("IMPLEMENT setGame method");

}

标签: java

解决方案


我相信,根据上下文,您应该填写或(maskedPhrase不是复制到)。喜欢,'*'' ' inputmaskedPhrase

public void setGame(char... input) {
    this.phrase = input;
    this.maskedPhrase = new char[input.length];
    Arrays.fill(this.maskedPhrase, '*');
}

推荐阅读