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
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();
// String result = "";
//write your code here
String[] a = s.split(" ");
StringBuffer sb = new StringBuffer();
for(int i=0; i<a.length; i++){
// result = result + Character.toUpperCase(a[i].charAt(0))+ a[i].substring(1)+" ";
sb.append(Character.toUpperCase(a[i].charAt(0)))
.append(a[i].substring(1)).append(" ");
}
String result = sb.toString().trim();
System.out.println(result);
}
}