import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
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++){
// System.out.println(s1.length);
String first = s1[i].substring(0,1).toUpperCase();
String last = s1[i].substring(1,s1[i].length());
s1[i] = first+last;
}
for(String s2 : s1)
System.out.print(s2+" ");
}
}
Couldn't pass 4th condition
Archived
Comments (2)
- Popular
- New
- Old
You must be signed in to leave a comment
Weichen Ouyang
13 August 2019, 23:23
I solved it by using trim() first, to eliminated the front and tailing spaces, and than alter the regular expression like following:
String[] splitted = s.trim().split("[ ]+");
0
Dusernajder
4 August 2019, 09:34
It would be better to attach you code via the little icon at the bottom when you ask a question, that way we could see the conditions too.
You should look up regular expressions: https://codegym.cc/groups/posts/regex-java
You should also look up the String class methods, by that, replace() would be more convenient, than what you were doing with that last variable: https://docs.oracle.com/javase/8/docs/api/
And just saying, look for redundant pieces in your code, don't waste your precious lines :D even if the "mistake" (it's not a mistake) you made doesn't take up a whole line. IntelliJ should warn you by making that part of the code grey.
0