C Programs Tutorials | IT Developer
IT Developer

Java Programs



Share with a Friend

Function Overload - String Program - Java Programs

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 = 3

void check(String s1) – to display only the vowels from string s1, after converting it to lowercase.

Example:

Input:
s1 = “computer”
Output:
o u e

class Overload{ public static void check(String str, char ch){ int count = 0; for(int i = 0; i < str.length(); i++){ if(ch == str.charAt(i)) count++; } System.out.println("Frequency = " + count); } public static void check(String s1){ s1 = s1.toLowerCase(); for(int i = 0; i < s1.length(); i++){ char ch = s1.charAt(i); switch(ch){ case 'a': case 'e': case 'i': case 'o': case 'u': System.out.print(ch + "\t"); } } } }

Output