So I have this and be aware that I only use simple methods such at toString(), charAt. Right now my code is just returning the original string, and I do not know why.
Ok, so I realized that after a few tests, the reason it is returning the original string is because in the nested if statement in the loop, the condition is never true, so it bypasses the if statement. Why is it never true?
System.out.print("Enter in a string: ");
String userInput = scan.nextLine();//string user enters
String vowelChar;//individual character within user's input
for (int i=0; i<userInput.length(); i++){
Character indChar = userInput.charAt(i);
vowelChar = indChar.toString();
if (vowelChar=="a" || vowelChar=="e" || vowelChar=="i" || vowelChar=="o" || vowelChar=="u"){
String beforeText = userInput.substring(0, i-1);//string before vowel
String afterText = userInput.substring(i+1);//string after vowel
userInput=beforeText+"_"+afterText;
}else{
//character is not a vowel
//do nothing
}
}
System.out.print(userInput);
}
}