In the ICSE board check() overloading problem, a class defines two void methods named check: check(String str, char ch) counts how many times ch appears in str, while check(String s1) converts s1 to lowercase and prints every vowel. Because one version accepts two arguments and the other accepts one, Java resolves each call unambiguously at compile time using length() and charAt() traversal.
- 1. Scanning Characters with length() and charAt()
- 2. Extracting Vowels After Lowercase Normalization
- 3. Safe Scanner Input for Strings and Characters
- 4. StringCheck.java β ICSE Overloaded check() for Char Frequency & Vowels
- 5. CISCE Variable Description Table (VDT) & Dry Run
- 6. Common Mistakes & Top Scorer Tips
- 7. Interactive Concept Check Quiz
- 8. Frequently Asked Questions
1. Scanning Characters with length() and charAt()
Finding how many times ch appears inside str requires inspecting every index from 0 up to str.length() - 1. In Java, str.charAt(i) extracts the character at index i as a primitive char, which you compare directly against ch using the equality operator == rather than .equals(). Each match increments an integer counter count initialized to 0 before the loop starts. Remember that 'S' and 's' have different Unicode values (83 versus 115), so preserve exact case matching unless the ICSE question explicitly asks for case-insensitive counting.
- Initialize count = 0 before entering the for loop over str.length().
- Use strict index bounds (0 <= i < str.length()) because string indexing begins at 0.
- Compare charAt(i) == ch with single quotes around char literals.
2. Extracting Vowels After Lowercase Normalization
To extract only vowels from s1, normalize the entire string first with s1 = s1.toLowerCase();. Because Java String objects are immutable, calling s1.toLowerCase() without assigning the result back to s1 leaves the original uppercase characters unchangedβa common Section B trap. Once s1 is lowercase, check each character c = s1.charAt(i) against 'a', 'e', 'i', 'o', and 'u' using logical OR (||), cutting the condition in half compared to testing ten uppercase and lowercase vowels.
- Reassign s1 = s1.toLowerCase() because String methods never mutate the original object.
- Test all five vowels explicitly: c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u'.
- Print vowels inline using System.out.print() and finish with System.out.println().
3. Safe Scanner Input for Strings and Characters
Console programs mixing Scanner tokens often fail when sc.nextLine() reads a leftover newline character right after sc.next() or sc.nextInt(). In our main() method, reading the first string with sc.nextLine(), extracting the single target character via sc.next().charAt(0), and inserting a dummy sc.nextLine() clears the input buffer cleanly before reading s1. Without that buffer-clearing line, s1 receives an empty string "" and prints zero vowels, even though the check(String) method logic itself is completely valid.
- Read full phrases including spaces using sc.nextLine() rather than sc.next().
- Consume the leftover newline character via sc.nextLine() after sc.next().charAt(0).
- Document loop variable i, count, and extracted char c clearly in your VDT.
4. StringCheck.java β ICSE Overloaded check() for Char Frequency & Vowels
import java.util.*;
public class StringCheck {
public void check(String str, char ch) {
int count = 0;
for (int i = 0; i < str.length(); i++) {
if (str.charAt(i) == ch) {
count++;
}
}
System.out.println("Frequency of '" + ch + "' = " + count);
}
public void check(String s1) {
s1 = s1.toLowerCase();
System.out.print("Vowels: ");
for (int i = 0; i < s1.length(); i++) {
char c = s1.charAt(i);
if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') {
System.out.print(c + " ");
}
}
System.out.println();
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
StringCheck obj = new StringCheck();
System.out.print("Enter a string for frequency check: ");
String str = sc.nextLine();
System.out.print("Enter character to count: ");
char ch = sc.next().charAt(0);
obj.check(str, ch);
sc.nextLine();
System.out.print("Enter a string to extract vowels: ");
String s1 = sc.nextLine();
obj.check(s1);
sc.close();
}
}
Verified Console / Dry-Run Output:
Enter a string for frequency check: success
Enter character to count: s
Frequency of 's' = 3
Enter a string to extract vowels: Computer Applications
Vowels: o u e a i a i o
5. CISCE Variable Description Table (VDT) & Dry Run
| Variable | Data Type | Exam Purpose & Sample Value |
|---|---|---|
| str | String | Input word or phrase for frequency search ("success") |
| ch | char | Target character counted inside check(String, char) ('s') |
| count | int | Accumulator tracking matching character occurrences (3) |
| s1 | String | Lowercased string scanned for vowels ("computer applications") |
| c | char | Current character extracted by s1.charAt(i) ('o', 'u', ...) |
| i | int | Loop index iterating from 0 to length() - 1 (0..6) |
Ace ICSE String Programs 1-on-1
Practice String manipulation, charAt() loops, and ICSE past-paper check() overloading questions live with an experienced Java tutor.
6. Common Mistakes & Top Scorer Tips
- Avoid Mistake: Writing str.charAt(i).equals(ch) instead of ==, which fails compilation because char is a primitive type.
- Avoid Mistake: Calling s1.toLowerCase(); without assigning it back to s1, leaving uppercase vowels undetected.
- Avoid Mistake: Using i <= str.length() in the loop condition, throwing StringIndexOutOfBoundsException on the final step.
- Examiner / Mentor Tip: Remember length() for String uses parentheses, whereas array .length does notβa classic Section A trap.
- Examiner / Mentor Tip: Do not confuse single quotes 'a' (char) with double quotes "a" (String) during vowel comparisons.
- Examiner / Mentor Tip: Keep both check() methods void as required by the ICSE 2019 pattern so no return statement is expected.
7. Interactive Concept Check Quiz
Question: What output does obj.check("Banana", 'a') produce in the StringCheck class?
8. Frequently Asked Questions
Why do we use == instead of .equals() when comparing characters in check()?
What happens if we write s1.toLowerCase(); without reassigning s1?
How do you read a single char safely using Scanner in BlueJ?
Explore Related Lessons & Free Interactive Tools
- All 110 Guides in ICSE Java BlueJ Library
- Method Overloading polygon() Pattern Program in Java (ICSE)
- ElectricBill Class Slab Calculation Program in Java (ICSE)
- RailwayTicket Class Program in ICSE Java (BlueJ)
- Interactive Tool: ICSE Class 10 Java BlueJ Output Quiz
- Interactive Tool: ICSE Variable Description Table (VDT) Auto-Formatter
