java - 使用java中的while循环将用户输入转换为星号之类的密码
问题描述
在java中使用while循环如何在输入密码时将用户输入转换为星号。这是可能的,如何?谢谢。
System.out.print("Enter password: ");
while(true)
{
password = pal.nextLine();
password = "*";
System.out.print(password);
}
这是我唯一的想法,但它不起作用
解决方案
不确定是否显示星号,但您可以使用该Console.readPassword
方法使密码不可见
public class Main {
public static void main(String[] args) {
char passwordArray[] = System.console().readPassword("Enter password: ");
// entered password will be stored in this array
}
}
推荐阅读
- python - Pygame [AI 汽车模型视觉] 中遮罩和发射光束之间的重叠
- java - 为什么我的 Android 套接字服务器在我的客户端触发套接字错误 10061
- python - Python:查找形状为 i,j,k 的数组中每个 i,j 组合的 k 方向最大值的位置
- javascript - 向 Flask 提交多个表单(400 BAD REQUEST)
- javascript - 如何将对象作为参数传递并在构造函数中引用它
- c++ - 你可以为一个没有创建的闭包添加一个上值吗?
- java - 如何在特定时区的特定语言环境中为人类格式化瞬间
- python - 在标题和正文中加载具有不同分隔符的 .tab 文件
- python - 带有使用 config.py 的 Python 烧瓶应用程序的 Gitlab CI?
- machine-learning - OneHotEncoding 2500 个不同的分类变量