The program should read a given String and find certain words with the following characteristics: start with 'p' and end with 'r' and start with 'h' and anywhere in the word have the letter 'o' . Since the word is identified it must be completely replaced with the symbol '#', keeping the total number of characters of the original word , (ie, the same amount of '#' must be the same than the number of letters the word originally has.
The program must return the complete String with the words identified replaced with the '#'. For example:
String text="the ants are eating what I just planted";
output: the ######## are eating what I just #######
I leave attached the code that I have so far:
public static void main(String[] args) {
Scanner leer = new Scanner(System.in);
System.out.println("TEXTO:");
String texto = leer.nextLine();
String arreglop[] = new String[texto.split(" ").length];
for (int i = 0; i < texto.split(" ").length; i++) {
char arreglol[] = new char[arreglop.length];
arreglop[i] = texto.split(" ")[i];
for (int j = 0; j < arreglop[i].length(); j++) {
arreglol[j] = arreglop[i].charAt(j);
if (arreglol[j] == 'p' || arreglol[j] == 'P') {
if (arreglol[arreglop[i].length()] == 'r' || arreglol[arreglop[i].length()] == 'R') {
for (int k = 0; k < arreglop[i].length(); k++) {
arreglol[k] = '#';
System.out.print(arreglol[k]);
}
}
} else if (arreglol[j] == 'h' || arreglol[j] == 'H') {
for (int k = 0; k < arreglop[i].length(); k++) {
if (arreglol[k] == 'o' || arreglol[k] == 'O') {
for (int l = 0; l < arreglop[i].length(); l++) {
arreglol[l] = '#';
System.out.print(arreglol[l]);
}
}
}
} else {
System.out.print(arreglop[i]);
}
}
}
}