Using while loop in java how can i convert user input into asterisk while it is being typed like in password. It is possible and how? Thanks.
System.out.print("Enter password: ");
while(true)
{
password = pal.nextLine();
password = "*";
System.out.print(password);
}
This is the only idea that i have but it doesn't work
Not sure about displaying asterisks but you could make the password invisible by using the Console.readPassword
method
public class Main {
public static void main(String[] args) {
char passwordArray[] = System.console().readPassword("Enter password: ");
// entered password will be stored in this array
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.