Design a class to overload a function check( ) as follows:

ICSE Class 10 Computer Applications PYQ · 2017 Paper · Section B

8Written · 2017 · Section B · 2017 Paper

Design a class to overload a function check( ) as follows:

Show SolutionHide Solution↓
public class KboatOverload
{
    void check (String str , char ch ) {
        int count = 0;
        int len = str.length();
        for (int i = 0; i < str.length(); i++) {
            char c = str.charAt(i);
            if (ch == c) {
                count++;
            }
        }
        System.out.println("Frequency of " + ch + " = " + count);
    }
    
    void check(String s1) {
        String s2 = s1.toLowerCase();
        int len = s2.length();
        System.out.println("Vowels:");
        for (int i = 0; i < len; i++) {
            char ch = s2.charAt(i);
            if (ch == 'a' ||
                ch == 'e' ||
                ch == 'i' ||
                ch == 'o' ||
                ch == 'u')
                System.out.print(ch + " ");
        }
    }
}
BlueJ output of KboatOverload.java BlueJ output of KboatOverload.java
← Previous questionNext question →

Browse the free Computer Applications sample bank