Hello,
I went down the string cutting way. so I have an array filled with words. I found an example on the internet and tried to modify it, but it didn't work out. There is some collision between String and Char.
I also found a conclusion about setCharAt, I tried but I don't know how to apply it.
"( setCharAt in defined for StringBuilder or StringBuffer not on String.
to change a char on string you have to covert it to either char array of a String buffer or builder.
Char array is a decent approach for you as you are playing with each and every character.
Go with the StringBuilder or StringBuffer approach, which will be easy to code, and the readability of the code also will be good.
Use whichever you are comfortable with. )".
I also saw one pretty simple solution on the help forum under my thread, it was from the archived thread. And I wonder whether to abandon my idea and make this simple uncomplicated solution.
package pl.codegym.task.task08.task0823;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;
/*
Ruszamy na cały kraj
*/
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String s = reader.readLine();
//tutaj wpisz swój kod
String[] arrayParts = s.split(" ");
for (String testPrint : arrayParts) // test print array
System.out.println(testPrint);
//String[] newArrayParts = new String[10];
//StringBuffer arrayParts = new StringBuffer(s1);
//String arrayParts = s1.toString();
//String newArrayParts = forarrayparts.toString();
for (String s1 : arrayParts) {
if (Character.isLowerCase(s1.charAt(0))) {
//Convert it into upper case using toUpperCase() function
arrayParts.setCharAt(0, Character.toUpperCase(s1.charAt(0))); // setCharAt why is red?
}
}
for (String testPrint : arrayParts) { // test print new array
System.out.println(testPrint);
}
for (String testPrint : arrayParts) { // final print
System.out.print(testPrint);
System.out.print(" ");
}
}
}