I am checking if last word is going to print ,then don't print extra space,still it is failing.Can someone check
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[] s1=s.split("\\s+");
for (int i = 0; i <s1.length ; i++) {
char[] c=s1[i].toCharArray();
c[0]=Character.toUpperCase(c[0]);
for (int j = 0; j <c.length ; j++) {
System.out.print(c[j]);
}
if(i==s1.length-1){
continue;
}
else {
System.out.print(" ");
}
}
}
}
String[] strings = s.trim().split("\\s+");
The trim() method removes spaces before the first non-space-character and after the last non-space-character.