You can know how many whitespaces
user entered by doing this:
Scanner sc = new Scanner(System.in);
System.out.println("Enter word with white-spaces:");
String str = sc.nextLine();
int totalSpace = str.split(" ").length-1;
System.out.println("total white-spaces is:"+totalSpace);
Edit: You can solve you problem by changing your while
condition like this:
while(!(guessedSpaces.replaceAll("\\d","").length()==3 && guessedSpaces.split(" ").length-1==3)){
.....
.....
System.out.println("Enter word with white-spaces:");
guessedSpaces = keyboard.nextLine();
}
4
solved How to check a string for white spaces