icse-promo

Question

Design a class to overload a function check() as follows:
i) void check(String str, char ch) – to find and print the frequency of a character
in a string.
Example :
Input — Output
Str = “success” number of s present is=3
ch = ‘s’
ii) void check (String s1) – to display only the vowels from string s1 , after converting it to lower case.
Example :
Input: S1= “computer”

output: o u e

Share code with your friends

Share on whatsapp
Share on facebook
Share on twitter
Share on telegram

Code

				
					public class program8
{
    public void check(String str, char ch) 
    {
        int result = 0,i=0;
        char ch1=' ';
        for (i = 0; i < str.length(); i++) 
        {
            ch1= str.charAt(i);
            if (ch == ch1)
            {
                result++;
            }
        }
        System.out.println("number of "+ch+" present is = " + result);

    }

    public void check(String s1)
    {
        int i=0;
        char ch=' ';
        s1 = s1.toLowerCase();
        for (i = 0; i < s1.length(); i++) 
        {
            ch = s1.charAt(i);
            if (ch == 'a' || ch == 'e' || ch == 'i' ||ch == 'o'||ch == 'u') 
            {
                System.out.print(ch + " " );
            }
        }
    }
}


				
			

Coding Store

Leave a Reply

Your email address will not be published. Required fields are marked *