I don't think there's a problem with spaces :/
package com.codegym.task.task08.task0823;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/*
Going national
*/
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String s = reader.readLine();
char[] array = s.toCharArray();
for(int i = 0; i < array.length - 1; i++) {
if(i == 0) {
char c = Character.toUpperCase(array[i]);
//System.out.println(c);
array[i] = c;
}else if (array[i] == ' ' && (i+1) <= array.length) {
char c = Character.toUpperCase(array[i + 1]);
array[i+1] = c;
// System.out.println(c);
}
}
System.out.println(array);
}
}