Python,C,C++ and JAVA programs for CBSE, ISC, B.Tech and I.T Computer Science and MCA students

The Programming Project: ICSE Java Programming Vowels in a String 2023 Q7 SPECIMEN PAPER

Friday, December 30, 2022

ICSE Java Programming Vowels in a String 2023 Q7 SPECIMEN PAPER

ICSE Java Programming Vowels in a String 2023 Q7 SPECIMEN PAPER

Question 7

Define a class to accept a string and print the same in reverse, also print the number of vowels in the string.

Eg:S="BEAUTIFUL"

Output - "LUFITUAEB" No. of vowels = 5


JAVA CODE ICSE Java programming Solved



import java.util.Scanner;

public class ICSEJava2023 {
    public static void main(String[] args) {
        StringReverse obj = new StringReverse();
        obj.inputString();
        obj.display();
    }
}

class StringReverse {
    public void inputString() {
        Scanner in = new Scanner(System.in);
        System.out.println("Enter a word:");
        this.message = in.nextLine();
        in.close();
    }

    public void display() {
        char[] c = new char[this.message.length()];
        System.out.println("Output");
        for (int i = 0; i < this.message.length(); i++) {
            System.out.print(this.message.charAt(this.message.length() - 1 - i));
            c[i] = this.message.charAt(i);
            if (c[i] >= 'a' || c[i] <= 'z')
                c[i] = (char) (c[i] - 32);
            for (int j = 0; j < 5; j++) {
                if (c[i] == this.vowels[j])
                    this.number_of_vowels++;
            }
        }
        System.out.println();
        System.out.println("No. of vowels:" + this.number_of_vowels);
    }
    StringReverse() {
        this.number_of_vowels = 0;
        this.message = "";
    }

    private int number_of_vowels;
    private String message;
    private static char[] vowels = { 'A', 'E', 'I', 'O', 'U' };
}

No comments:

Post a Comment