Ii am having trouble my below code I am building a project which requires the user to input ("This is some \"really\" great. (Text)!?") which is then converted into THISISSOMEREALLYGREATTEXT and the value is passed into the next parameter. then in my Obify method I am attempting to add OB in front of every vowel (AEIOUY) but in my function it does not do this effectively, it prints out THISISSOMEREALLYGREATTEXT numerous times and with each new time it passes THISISSOMEREALLYGREATTEXT it adds in OB at the end when I need OB infront of every vowel instead of just at the end. please do show me where I am going wrong so I can continue to progress. once again thank you in advance and the code under review is below.
import java.util.*;
public class Main {
public static void main(String[] args) {
normalizeText();
obify("THISISSOMEREALLYGREATTEXT" );
}
// Part 1 Normalized Method to convert all letter to uppercase and removing all special characters and placing it into String codey.
public static String normalizeText (){
Scanner sc = new Scanner( System.in );
String normText;
System.out.println("Please input text to encrypt");
normText = sc.nextLine();
System.out.println(normText.replaceAll(" ","").replaceAll("[^a-zA-Z ]", "").toUpperCase());
return normText;
}
//This method will take in the Normalized text and insert a capital O and B in-front of every vowel and return the text
private static String obify (String input) {
String obifiledInput = input;
for (int i = 0; i < input.length(); i++) {
if (input.contains( Character.toString( input.charAt( i ) ) )) {
obifiledInput = obifiledInput + "OB" + Character.toString( input.charAt( i ) );
} else {
obifiledInput = obifiledInput + Character.toString( input.charAt( i ) );
}
System.out.println(obifiledInput);
}
return obifiledInput;
}
}
Aucun commentaire:
Enregistrer un commentaire