public static void main(String[] args) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); String s = reader.readLine(); String result = ""; //write your code here String[] a = s.split(" "); for(int i=0; i<a.length; i++){ result = result + Character.toUpperCase(a[i].charAt(0))+ a[i].substring(1)+" "; } System.out.println(result); } How to handle when there is multiple spaces between the line