java - 需要帮助在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");
}
解决方案
我相信,根据上下文,您应该填写或(maskedPhrase
而不是复制到)。喜欢,'*'
' '
input
maskedPhrase
public void setGame(char... input) {
this.phrase = input;
this.maskedPhrase = new char[input.length];
Arrays.fill(this.maskedPhrase, '*');
}
推荐阅读
- css - 在网格模板列中优先考虑第二个值
- javascript - 如何在 foreach 内部的钩子中更新数组状态
- javascript - 如何在js中编写html
- yii - yii2-multiple-input - 在中间添加和删除行
- loops - 用地图功能替换_na
- spring-boot - 如何使用 Spring 集成处理大文件
- c++ - 使用 VCPKG 在 Visual Studio 上安装 geos
- amazon-web-services - 将位置历史记录 REST API 转换为 AWS 位置 ping 的“云原生”方式是什么?
- c# - .Net Core OData 以不同方式序列化日期时间
- asp.net - 如何编写一个存储过程/函数来返回一个对象列表,该列表还包含一个列表作为其属性给 C#