Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/339.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ssl/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在java中使用while循环将用户输入转换为类似星号的密码_Java - Fatal编程技术网

在java中使用while循环将用户输入转换为类似星号的密码

在java中使用while循环将用户输入转换为类似星号的密码,java,Java,在java中使用while循环时,如何将用户输入转换为星号,就像在密码中一样。这是可能的,如何实现?谢谢 System.out.print("Enter password: "); while(true) { password = pal.nextLine(); password = "*"; System.out.print(password); } 这

在java中使用while循环时,如何将用户输入转换为星号,就像在密码中一样。这是可能的,如何实现?谢谢

        System.out.print("Enter password: ");

        while(true)
        {
            password = pal.nextLine();
            password = "*"; 
            System.out.print(password);
        }

这是我唯一的想法,但它不起作用

不确定是否显示星号,但您可以使用
控制台。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        
  }
}

不确定是否显示星号,但可以使用
控制台.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        
  }
}


一个变量用于实际密码,另一个变量用于显示Asterixes您不能在命令提示符中执行此操作。您可以打印x行,使屏幕看起来已被清除,或者在某处搜索clearScreen功能,并打印正确数量的*,但这是不同的。@ScaryWombat当然,但是密码仍然会显示在屏幕上。@Stultuske抱歉,它在哪里说明了有关命令行的内容?@ScaryWombat你能给我看一下你的密码吗?请并感谢一个变量用于实际密码,另一个变量用于显示Asterix。您不能在命令提示符中执行此操作。您可以打印x行,使屏幕看起来已被清除,或者在某处搜索clearScreen功能,并打印正确数量的*,但这是不同的。@ScaryWombat当然,但是密码仍然会显示在屏幕上。@Stultuske抱歉,它在哪里说明了有关命令行的内容?@ScaryWombat你能给我看一下你的密码吗?请和我一起做这个?你是说打印星号?可以,但我不认为有直接的方法,你可能需要做一些调整。请看一下这个@Dewormwood为什么你需要一个while循环?@Stultuske,因为我看过一个视频回答了我的问题,他使用while循环。那么,你看过一个视频,它的代码完全符合你的需要?为什么不使用那个代码呢?不管怎样,我认为如果你尝试Srt的解决方案,你会发现你不需要loopCan,而loop可以这样做?你是说打印星号?可以,但我不认为有直接的方法,你可能需要做一些调整。请看一下这个@Dewormwood为什么你需要一个while循环?@Stultuske,因为我看过一个视频回答了我的问题,他使用while循环。那么,你看过一个视频,它的代码完全符合你的需要?为什么不使用那个代码呢?不管怎样,我认为如果你尝试Srt的解决方案,你会发现你不需要一个循环