I have tried debugging this code, and just cannot find what is wrong.
I am trying to eliminate spaces and capitalize any instance of the word "I" with this code. Then I am trying to put the sentence back together with only one space in between the words. As of right now, if there are 4 spaces in the original string, there will still be 4 spaces in the revised string.
Thanks
public class Sentencefix {
public static void main(String[] args) {
System.out.println("Enter your input sentece");
String input = IO.readString();
String[] arr = input.split(" ");
for (int i = 0; i < arr.length; i++) {
arr[i] = arr[i].trim();
arr[i] = arr[i].toLowerCase();
if (arr[i] == "i") {
arr[i] = arr[i].toUpperCase();
}
}
input = "";
for (int j = 0; j < arr.length; j++) {
input = input + ' ' + arr[j];
}
input = input.trim();
char ch = input.charAt(0);
ch = Character.toUpperCase(ch);
input = ch + input.substring(1, input.length());
if (input.charAt(input.length() - 1) != '.' && input.charAt(input.length() - 1) != '!' && input.charAt(input.length() - 1) != '?') {
input = input + '.';
}
System.out.println(input);
}
}
edit posted the whole code