Edit:
I've tried to compile all of the code into a single program. Now all I need is to figure out how to return the modified string from the method. What do I have to put in order to achieve this?
Here's the new code:
public class String_Fixer {
public static void main(String[] args) {
String userInput, newString;
Scanner keyboard = new Scanner(System.in);
System.out.println("This program takes sentences and capitalizes them for you.");
System.out.println("Please write a few sentences.");
System.out.println("");
userInput = keyboard.nextLine();
System.out.println("");
System.out.println("Here is the original sentence:");
System.out.println(userInput);
System.out.println("");
System.out.println("And here is the modified sentence:");
System.out.println();
}
public static List<Integer> stringFixer(String userInput) {
List<Integer> indexes = new ArrayList<>();
int first = 0, offset = 2, index, offset_index;
while ((index = userInput.indexOf('.', first)) != -1) {
offset_index = index + offset;
if (offset_index < userInput.length()) {
indexes.add(offset_index);
}
first = index + 1;
}
while ((index = userInput.indexOf('?', first)) != -1) {
offset_index = index + offset;
if (offset_index < userInput.length()) {
indexes.add(offset_index);
}
first = index + 1;
}
return indexes;
}
public static String CapatilizeChars(List<Integer> indexes, String string) {
StringBuilder newString = new StringBuilder(string);
for (int i : indexes) {
char capChar = Character.toUpperCase(newString.charAt(i));
newString.setCharAt(i, capChar);
}
return newString.toString();
}
}