Define a class to accept a string and convert the same to uppercase, create and display the new string by replacing each vowel by immediate next character and…

ICSE Class 10 Computer Applications PYQ · 2025 Specimen · Section B

5Written · 2025 · Section B · 2025 Specimen

Define a class to accept a string and convert the same to uppercase, create and display the new string by replacing each vowel by immediate next character and every consonant by the previous character. The other characters remain the same.

Example:
Input : #IMAGINATION@2024
Output : #JLBFJMBSJPM@2024

Show SolutionHide Solution↓
import java.util.Scanner;

public class KboatStringConvert
{
    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        System.out.print("Enter a string: ");
        String str = in.nextLine();
        str = str.toUpperCase();
        int l = str.length();
        
        String res = "";
        
        for (int i = 0; i < l; i++) {
            char ch = str.charAt(i);
            if ("AEIOU".indexOf(ch) != -1) {
                res += (char)(ch + 1);
            }
            else if (Character.isLetter(ch)) {
                res += (char)(ch - 1);
            }
            else {
                res += ch;
            }
        }
        
        System.out.println("Output String:");
        System.out.println(res);
    }
}
BlueJ output of KboatStringConvert.java
← Previous questionNext question →

Browse the free Computer Applications sample bank