Hello all,
My programme meets the task requirements in that it capitalises the first letter of every string, but for some reason it can't pass the 3rd condition. I have inputted a bunch of difference sentences to see if it would work and it's perfect every time. Could anyone let me know why my code is failing to meet the 3rd condition?
package com.codegym.task.task08.task0823;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
/*
Going national
*/
public class Solution {
public static void main(String[] args) throws IOException {
Scanner scanner = new Scanner(System.in);
String s = scanner.nextLine();
String[] list = s.split(" ");
for(int i = 0; i < list.length; i++)
{
String x = list[i];
if(i == list.length - 1)
{
System.out.print(x.substring(0, 1).toUpperCase() + x.substring(1));
break;
}
System.out.print(x.substring(0, 1).toUpperCase() + x.substring(1) + " ");
}
}
}