Hi, I'm trying to get the last condition fullfilled but I'm not sure how to get rid of the last space after the last word.
I tried adding this
for (int i = 0; i <s1.length ; i++) {
char[] c=s1[i].toCharArray();
c[0]=Character.toUpperCase(c[0]);
k++;
for (int j = 0; j <c.length ; j++) {
System.out.print(c[j]);
}
if(i==s1.length-1){
continue;
}
else if (k < s.length) {
System.out.print(" ");
}
else {
System.out.println();
}
but to no avail. Any help?
Thanks
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(" ");
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(" ");
}
}
System.out.println();
}
}