Computer Applications
Design a class to overload a function check( ) as follows:
void check (String str , char ch ) — to find and print the frequency of a character in a string.
Example:
Input:
str = "success"
ch = 's'
Output:
number of s present is = 3void check(String s1) — to display only vowels from string s1, after converting it to lower case.
Example:
Input:
s1 ="computer"
Output : o u e
Java
User Defined Methods
ICSE 2017
60 Likes
Answer
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 + " ");
}
}
}
Variable Description Table
Program Explanation
Output
![BlueJ output of Design a class to overload a function check( ) as follows: (a) void check (String str , char ch ) — to find and print the frequency of a character in a string. Example: Input: str = "success" ch = 's' Output: number of s present is = 3 (b) 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 BlueJ output of Design a class to overload a function check( ) as follows: (a) void check (String str , char ch ) — to find and print the frequency of a character in a string. Example: Input: str = "success" ch = 's' Output: number of s present is = 3 (b) 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](https://cdn1.knowledgeboat.com/img/abp10/1/2017-p8-1.jpg)
![BlueJ output of Design a class to overload a function check( ) as follows: (a) void check (String str , char ch ) — to find and print the frequency of a character in a string. Example: Input: str = "success" ch = 's' Output: number of s present is = 3 (b) 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 BlueJ output of Design a class to overload a function check( ) as follows: (a) void check (String str , char ch ) — to find and print the frequency of a character in a string. Example: Input: str = "success" ch = 's' Output: number of s present is = 3 (b) 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](https://cdn1.knowledgeboat.com/img/abp10/1/2017-p8-2.jpg)
Answered By
25 Likes
Related Questions
Invoking a method by passing the objects of a class is termed as:
- Call by reference
- Call by value
- Call by method
- Call by constructor
Using switch statement write a menu driven program to overload a function series as follows:
(a) void series() — To find and display the sum of the following series:
S = 2 - 4 + 6 - 8 + 10 ….. - 20(b) void series(int n, int x) — To find and display the sum of the following series:
S = (x2 / 1!) + (x4 / 3!) + (x6 / 5!) + ……. to n termsParameters that are passed to the called method during the method call are termed as …………… parameters.
Consider the following program segment and answer the questions below:
class calculate { int a; double b; calculate() { a=0; b=0.0; } calculate(int x, double y) { a=x; b=y; } void sum() { System.out.println(a*b); }}
Name the type of constructors used in the above program segment?