ICSE Java Programming Design a class to overload a function 2017 Q8 Solved
import java.util.Scanner;
public class ICSEJava {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String s;
char c;
System.out.println("Enter the string");
s = in.nextLine();
System.out.println("Enter the character");
c = in.nextLine().charAt(0);
StringCheck obj = new StringCheck();
obj.check(s, c);
obj.check(s);
in.close();
}
}
class StringCheck {
public void check(String str, char ch) {
for (int i = 0; i < str.length(); i++) {
if (ch == str.charAt(i))
counter++;
}
System.out.println("Number of times " + ch + " present is " + counter);
}
public void check(String str) {
str = str.toLowerCase();
for (int i = 0; i < str.length(); i++) {
if (str.charAt(i) == 'a' || str.charAt(i) == 'e' || str.charAt(i) == 'i' || str.charAt(i) == 'o'
|| str.charAt(i) == 'u')
System.out.print(str.charAt(i) + " ");
}
}
StringCheck() {
counter = 0;
}
private int counter;
}