9
I was given an exercise in which I have to write a program that reads a word in the interval [1-20] and encrypt this word using the steps:
- reverse the word
- where there is a vowel, replace with the next vowel
And display the encrypted word.
I know how to do the word reversal part, but replacing vowels I’ve tried several ways and I couldn’t. 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();
}
}
This range from 1 to 20 is the word size?
– gato
That’s why I put the while one
– Francine Stivanin
Do you have any example of how the final output of the program should look? Example, if I feed with the word
abcei
, what kind of output it should generate?– gato