Program opened below. You can scroll through the algorithm, Java code and output.

Replace Vowels with the Succeeding Letter

Download .java

Question

Replace each vowel in an entered sentence with the succeeding alphabetic letter.

Step 1: Start the program and accept a complete sentence. Step 2: Store the original sentence for display after conversion. Step 3: Initialise an empty string to store the modified sentence. Step 4: Visit each character from the first position to the last. Step 5: Store the current character in a character variable. Step 6: Check whether the character is a lowercase or uppercase vowel. Step 7: If it is a vowel, replace it with the succeeding alphabetic character. Step 8: Leave consonants, spaces, punctuation and other characters unchanged. Step 9: Append the resulting character to the modified sentence. Step 10: Repeat until all characters have been examined. Step 11: Display the original sentence on one line. Step 12: Display the modified sentence on the next line and stop.
Java
import java.util.*;
class VowelSuccessor
{
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        System.out.print("Enter a sentence: ");
        String s = sc.nextLine();
        String result = "";
        for (int i = 0; i < s.length(); i++)
        {
            char ch = s.charAt(i);
            switch (ch)
            {
                case 'a': ch = 'b';
                break;
                case 'e': ch = 'f';
                break;
                case 'i': ch = 'j';
                break;
                case 'o': ch = 'p';
                break;
                case 'u': ch = 'v';
                break;
                case 'A': ch = 'B';
                break;
                case 'E': ch = 'F';
                break;
                case 'I': ch = 'J';
                break;
                case 'O': ch = 'P';
                break;
                case 'U': ch = 'V';
                break;
            }
            result += ch;
        }
        System.out.println("Original: " + s);
        System.out.println("New sentence: " + result);
    }
}
Input: COMPUTER APPLICATION Output: Original: COMPUTER APPLICATION New sentence: CPMPVTFR BPPLJCBTJPN
← Previous Program 43 of 84 Next →

Share a comment or request a program

Use this form to send a comment, report an issue, or suggest a new practical. Your message will be saved for review by the school.