I need to write a little program in Java that asks a person to enter a Pin Code. So I need the Pin to be hidden with asterisks (*) instead of the numbers. How can I do that?
So far, this is my code :
import java.util.Scanner;
import java.io.*;
public class codePin {
public static void main(String[] args){
int pinSize = 0;
do{
Scanner pin = new Scanner(System.in);
System.out.println("Enter Pin: ");
int str = pin.nextInt();
String s = new Integer(str).toString();
pinSize = s.length();
if(pinSize != 4){
System.out.println("Your pin must be 4 integers");
} else {
System.out.println("We're checking if Pin was right...");
}
}while(pinSize != 4);
}
}
Actually this program works for now, but I want to add a functionality to display Pin like "* * * " or " * *" etc... (in the console when the Person enters is own Pin). I found something to entirely hide the Pin, but I do not want this. I want the Pin with asterisks
Any ideas ? Thanks