My code does exactly what is asked, yet it fails!
package com.codegym.task.task08.task0823;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Locale;
/*
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();
//write your code here
String c;
if (s != null) c = s.trim();
else c = "";
String[] words = s.split(" ");
String result = "";
for(String w : words){
if (w.length() > 1)
result += w.substring(0, 1).toUpperCase() + w.substring(1, w.length()).toLowerCase() + " ";
else result += w + " ";
}
System.out.println(result);
}
}