There is a string consisting of numbers that are separated by a space, one number can not be more than 100. I need to check that the entered numbers are separated only by one space. If there is one space, I return true; if there is more than one, then I return false. I’ve made a check for the fact that the line contains only numbers and spaces, but the number of spaces doesn’t work. Here is what I could write:
private static boolean checkDigital(String word)throws Exception{ if (word == null) throw new Exception("Not text"); for (int i = 0; i < word.length(); i++) { char c = word.charAt(i); if (!Character.isDigit(c) && c != ' '){ return false; } } return true; } Tell me how to properly validate the number of spaces between numbers.