I was given an exercise in which I have to write a program that reads a word in the range [1-20] and encrypts this word using the steps:
- Reverse the word
- where you have a vowel, replace with the next vowel
And display the word encrypted.
I can do the reverse part of the word, but replacing the vowels I've tried in several ways and I could not. Here's what I've been able to do so far:
package ExerciciosPackage02;
import java.util.Scanner;
public class ExerciciosClass01h {
static Scanner ler=new Scanner(System.in);
static String palavra;
public static void lerpalavra(int ini, int fim){
System.out.println("Digite uma palavra:");
do{
System.out.print("-> ");
palavra=ler.nextLine();
}while ((palavra.length()<ini)||(palavra.length()>fim));
}
public static void inverter(){
int ctcar;
System.out.print("Criptografia: ");
for(ctcar=palavra.length()-1;ctcar>=0;ctcar--){
System.out.print(palavra.charAt(ctcar));
}
}
public static void invertvogal(){
//int ctcar;
//System.out.println(palavra.replaceAll("a", "e"));
//for(ctcar=palavra.length()-1;ctcar>=0;ctcar--){
//}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
lerpalavra(1,20);
inverter();
invertvogal();
}
}