public class Main {
public static void main(String[] args) throws Exception {
String name = "eric";
String nameForYou = name.replaceAll(".","*");
String afterGuess="";
System.out.println("Guess my name: "+nameForYou+" "+name.length());
String yourguess = "c";
for (int i=0;i<name.length();i++) {
if ((yourguess.charAt(0) == name.charAt(i))){
afterGuess = nameForYou.replace(nameForYou.charAt(i),yourguess.charAt(0));
}
}
System.out.println(afterGuess);
}
}
I want output as:
Guess my name: **** 4
***c
I don't want it to replace all the "*"