Create a free account on Computer Sir Ki Class and unlock access to valuable learning resources.
Exam Paper Downloads: After registering and logging in, you can download exam question papers in PDF format to practice and prepare for your exams.
Student Support: Get assistance with your doubts, queries, and questions related to your studies. Our support is here to help you understand topics and resolve your learning difficulties.
Register today and make your exam preparation easier and more effective!
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’
[15]
(ii) void check(String s1) – to display only vowels from string s1, after converting it to lower case.
Example :
Input:
s1 =”computer” Output : o u e
Answer:
public class Overload {
public void check(String str, char ch) {
int result = 0;
for (int i = 0; i < str.length(); i++) {
char currentChar = str.charAt(i);
if (ch == currentChar) {
result++;
}
}
System.out.println("number of s present is = " + result);
}
public void check(String s1) {
s1 = s1.toLowerCase();
for (int i = 0; i < s1.length(); i++) {
char currentChar = s1.charAt(i);
if (currentChar == 'a' || currentChar == 'e' || currentChar == 'i' || currentChar == 'o'
|| currentChar == 'u') {
System.out.print(currentChar + " " );
}
}
}
}
C. Sir| Created: 15-Apr-2019 | Updated: 15-Apr-2019|ICSE2017