08A-2017 – Computer Sir Ki Class

Login


Lost your password?

Don't have an account ?
Register (It's FREE) ×
  

Login
[lwa]



Exam Questions-ICSE2017-08A #JAVA#7264    siteicon   siteicon  

Problem Statement - 08A-2017

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

Solution

TC++ #7264

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 + " " );
 }
 }
 }
 }


Share

CSKC| Created: 15-Apr-2019 | Updated: 15-Apr-2019|ICSE2017









Back