★★★★★
"The one step solution for my son. Modern Age Coders make learning coding so simple that kids love it. The teachers explain complex concepts clearly with practical exercises and interactive content."
Ria Mukherjee
Parent
ICSE Class 10 · Computer Applications (Java) · String programs 2027
ICSE Class 10 string programs are the Section B questions that hand you a word or a sentence and ask you to take it apart character by character. This page carries six complete programs that work on whole sentences, each with Scanner input, comments, a variable description table and a sample run copied from Java 21, plus a cheat table of the String functions and what each one returns. In our live mini batch the same programs are written on paper first and then run in BlueJ in front of the group.
Live online · six full string programs · String functions cheat table · every sample run from real Java · first class free
Start here
The ICSE Java course in which the mini batch writes these programs, the Class 11 and 12 Computer Science course where string handling returns at ISC depth, and Java for Teens for a younger sibling or anyone who wants Java without a board paper attached.

The batch / ICSE CA
Class 9 and 10 Computer Applications in a mini batch, with a string handling program written and run every fortnight.
Open the course →
Next step / ISC
For students heading to ISC Computer Science, where sentence programs grow into word sorting and text processing.
Open the course →
Second language / Python
For the student who enjoys text puzzles and wants to see the same string ideas in a second language after the board exam.
Open the course →Ans. The short version
ICSE Class 10 string programs ask you to read a word or sentence with Scanner and process it one character at a time with charAt, length, indexOf, substring and the Character methods. The families the board returns to are palindrome words, Pig Latin, letter frequency, word extraction (counting, capitalising, finding the longest word), coding by shifting letters and spotting double letters. Each answer earns its marks through a working loop, correct method use, comments and a variable description table. Modern Age Coders teaches these live in a Tuesday and Wednesday mini batch in India, or personalised one to one at the family's time.
Q1. What kinds of string programs does ICSE set?
Nearly every Section B string question belongs to one of six families, and all six rest on one loop: walk the string with charAt from index 0 to length() minus 1. Learn the family, and an unseen question becomes a small change to a program you already know.
| Family | What the question asks | The key idea | Program below |
|---|---|---|---|
| Palindrome | Check a word, or print every palindrome word in a sentence | Build the reverse with a backward loop, compare with equals | Program 1 |
| Pig Latin | Move the letters before the first vowel to the end and add AY | indexOf on "AEIOU" finds a vowel; two substrings rebuild the word | Program 2 |
| Frequency | Count each letter, vowel or character in a string | An int array of 26 counters, indexed by ch minus 'A' | Program 3 |
| Word handling | Capitalise each word, count words, find words with a property | A word starts where the character before it is a space | Program 4 |
| Coding | Shift each letter a fixed number of places, keep other characters | Character arithmetic with % 26 so Z wraps round to A | Program 5 |
| Pairs and lengths | Double letters, consecutive letters, the longest word | Compare charAt(i) with charAt(i + 1) inside the bounds | Program 6 |
Four of the six programs need the words of a sentence one at a time. The ICSE way, without split, is to add one space to the end of the sentence so the last word is closed like the others, then build each word letter by letter:
nextLine(), then trim() it and add " " at the end.w.w is not empty, the word is complete: process it.w = "" and carry on. The extra space guarantees the last word is processed too.The programs hub keeps one short example of each program shape across the whole syllabus: ICSE Class 10 Java programs for practice.
Q2. Which String functions must you know?
These are the String methods ICSE Class 10 programs and output questions lean on. Every result in the last column was printed by Java 21. Learn the return type as well as the value: an int, a char, a boolean and a String are four different answers.
| Method | Returns | Example | Result |
|---|---|---|---|
length() | int | " Board Exam ".length() | 14 |
trim() | String | " Board Exam ".trim() | Board Exam |
charAt(int) | char | "COMPUTER".charAt(3) | P |
indexOf(char) | int | "COMPUTER".indexOf('U') and indexOf('Z') | 4 and -1 |
lastIndexOf(char) | int | "BANANA".lastIndexOf('A') | 5 |
substring(int) | String | "COMPUTER".substring(3) | PUTER |
substring(int, int) | String | "COMPUTER".substring(3, 6) | PUT |
toLowerCase() / toUpperCase() | String | "COMPUTER".toLowerCase(), "java".toUpperCase() | computer, JAVA |
replace(char, char) | String | "PAPER".replace('P', 'T') | TATER |
concat(String) | String | "ICSE".concat("2027") | ICSE2027 |
equals / equalsIgnoreCase | boolean | "Java".equals("JAVA"), "Java".equalsIgnoreCase("JAVA") | false, true |
compareTo(String) | int | "APPLE".compareTo("ANT") | 2 |
compareToIgnoreCase(String) | int | "apple".compareToIgnoreCase("APPLE") | 0 |
startsWith / endsWith | boolean | "ICSE".startsWith("IC"), "BlueJ".endsWith("j") | true, false |
String.valueOf | String | String.valueOf(45) + 5 | 455 |
The end index is excluded, so the result has 6 minus 3, that is three, characters. The commonest slip in the whole table.
"APPLE" and "ANT" first differ at P and N. P is code 80 and N is 78, so the answer is 2, not 1 and not true.
A String never changes. s.toUpperCase(); on its own line does nothing useful; write s = s.toUpperCase();.
Character tests such as isLetter, isUpperCase and toUpperCase, used in Programs 3 to 5, are covered with the wrapper classes on
wrapper and library classes for ICSE Class 10, and String results as one-mark traps are on
ICSE Computer Applications output questions.
Q3. How do you write the palindrome word and Pig Latin programs?
A palindrome word reads the same backwards, such as NOON. The board version usually goes one step further and asks for every palindrome word in a sentence, which is the word-extraction template with a reverse check inside it.
import java.util.Scanner;
class PalinWords {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter a sentence in capitals:");
String s = sc.nextLine().trim() + " "; // a space at the end closes the last word
String w = ""; // the word being built
int count = 0;
for (int i = 0; i < s.length(); i++) {
char ch = s.charAt(i);
if (ch != ' ') {
w = w + ch;
} else if (w.length() > 0) {
String rev = "";
for (int j = w.length() - 1; j >= 0; j--)
rev = rev + w.charAt(j);
if (w.equals(rev)) {
System.out.print(w + " ");
count++;
}
w = ""; // start the next word
}
}
System.out.println();
System.out.println("Number of palindrome words = " + count);
}
}
equals is used, not ==, because two Strings with the same letters can be different objects.
| Variable | Type | Purpose |
|---|---|---|
| s | String | the sentence, with one space added at the end |
| w | String | the word being built |
| rev | String | w written backwards |
| ch | char | the current character |
| count | int | number of palindrome words |
| i, j | int | loop counters |
Enter a sentence in capitals: MOM AND DAD SAW A RACECAR AT NOON MOM DAD A RACECAR NOON Number of palindrome words = 5
A single letter, A, counts: it reads the same both ways. SAW reversed is WAS, so it is left out.
Pig Latin moves the letters before the first vowel to the end of the word and adds AY, so TRAIN becomes AINTRAY. The method pig handles one word, which makes the main loop short and lets you show a user-defined method, something examiners reward.
import java.util.Scanner;
class PigLatinLine {
// returns the Pig Latin form of one word in capitals
static String pig(String w) {
for (int i = 0; i < w.length(); i++) {
char ch = w.charAt(i);
if ("AEIOU".indexOf(ch) >= 0)
return w.substring(i) + w.substring(0, i) + "AY";
}
return w + "AY"; // no vowel: just add AY
}
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter a sentence:");
String s = sc.nextLine().trim().toUpperCase() + " ";
String w = "", out = "";
for (int i = 0; i < s.length(); i++) {
char ch = s.charAt(i);
if (ch != ' ')
w = w + ch;
else if (w.length() > 0) {
out = out + pig(w) + " ";
w = "";
}
}
System.out.println(out.trim());
}
}
"AEIOU".indexOf(ch) >= 0 is a one-line vowel test: it is -1 for any consonant.
| Variable | Type | Purpose |
|---|---|---|
| w (in pig) | String | one word in capitals |
| s | String | the sentence in capitals, space added |
| w (in main) | String | the word being built |
| out | String | the converted sentence |
| ch | char | the current character |
| i | int | loop counter |
Enter a sentence: robot can spy the train OBOTRAY ANCAY SPYAY ETHAY AINTRAY
SPY has no vowel from A, E, I, O, U, so the method returns SPY plus AY. Write that rule into your answer as a comment.
Number palindromes are a different program, built with % 10 and / 10, and they live with the other number families on special number programs in Java for ICSE.
Q4. How do you find the frequency of characters in Java?
Use an int array of 26 counters. Convert the string to capitals, and for every letter add one to f[ch - 'A']: 'A' lands in f[0], 'B' in f[1] and 'Z' in f[25]. One pass counts the whole alphabet, which is faster and shorter than 26 separate loops.
import java.util.Scanner;
class LetterFreq {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter a string:");
String s = sc.nextLine().toUpperCase();
int f[] = new int[26]; // f[0] counts A, f[25] counts Z
for (int i = 0; i < s.length(); i++) {
char ch = s.charAt(i);
if (Character.isLetter(ch))
f[ch - 'A']++;
}
System.out.println("Letter\tFrequency");
for (int k = 0; k < 26; k++) {
if (f[k] > 0)
System.out.println((char) (k + 'A') + "\t" + f[k]);
}
}
}
(char) (k + 'A') turns the counter number back into its letter for printing.
| Variable | Type | Purpose |
|---|---|---|
| s | String | the input in capitals |
| f | int[] | 26 counters, one per letter |
| ch | char | the current character |
| i, k | int | loop counters |
Enter a string: Board Exam Revision Letter Frequency A 2 B 1 D 1 E 2 I 2 M 1 N 1 O 2 R 2 S 1 V 1 X 1
Spaces are skipped by isLetter, and letters that never appear are not printed because of the f[k] > 0 test.
import java.util.Scanner;
class TitleVowel {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter a sentence:");
String s = sc.nextLine().trim().toLowerCase();
String out = "";
int v = 0;
for (int i = 0; i < s.length(); i++) {
char ch = s.charAt(i);
boolean first = (i == 0 || s.charAt(i - 1) == ' ');
if (first && ch != ' ') {
if ("aeiou".indexOf(ch) >= 0)
v++; // word begins with a vowel
out = out + Character.toUpperCase(ch);
} else
out = out + ch;
}
System.out.println(out);
System.out.println("Words beginning with a vowel = " + v);
}
}
A word begins at index 0, or wherever the previous character is a space. The || short-circuits, so charAt(i - 1) is never asked for when i is 0.
| Variable | Type | Purpose |
|---|---|---|
| s | String | the sentence in small letters |
| out | String | the sentence with capitals added |
| ch | char | the current character |
| first | boolean | true when ch starts a word |
| v | int | words beginning with a vowel |
| i | int | loop counter |
Enter a sentence: an apple a day keeps exams easy An Apple A Day Keeps Exams Easy Words beginning with a vowel = 5
The five are an, apple, a, exams and easy.
Q5. What about coding messages and double letters?
These two families test character arithmetic and careful bounds. A letter shift adds a number to a char and uses % 26 to wrap from Z back to A; a double-letter check compares each character with the next one and must stop one place before the end.
import java.util.Scanner;
class ShiftCode {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter a message:");
String s = sc.nextLine();
String code = "";
for (int i = 0; i < s.length(); i++) {
char ch = s.charAt(i);
if (Character.isUpperCase(ch))
ch = (char) ('A' + (ch - 'A' + 2) % 26);
else if (Character.isLowerCase(ch))
ch = (char) ('a' + (ch - 'a' + 2) % 26);
code = code + ch; // digits, spaces, signs unchanged
}
System.out.println("Coded: " + code);
}
}
ch - 'A' gives the letter's place, 0 to 25. Adding 2 and taking % 26 keeps it in range, so Y becomes A and Z becomes B.
| Variable | Type | Purpose |
|---|---|---|
| s | String | the original message |
| code | String | the coded message |
| ch | char | the current character, then its coded form |
| i | int | loop counter |
Enter a message: Meet at Zoo, 7 pm Coded: Oggv cv Bqq, 7 ro
Case is kept, Z wraps to B, and the comma, space and 7 pass through untouched.
import java.util.Scanner;
class DoubleLetters {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter a sentence in capitals:");
String s = sc.nextLine().trim() + " ";
int pairs = 0;
String w = "", big = "";
for (int i = 0; i < s.length(); i++) {
char ch = s.charAt(i);
if (i < s.length() - 1 && ch != ' ' && ch == s.charAt(i + 1))
pairs++; // same letter twice in a row
if (ch != ' ')
w = w + ch;
else {
if (w.length() > big.length())
big = w; // keeps the first longest word
w = "";
}
}
System.out.println("Double letter pairs = " + pairs);
System.out.println("Longest word = " + big + " (" + big.length() + " letters)");
}
}
The test i < s.length() - 1 comes first, so charAt(i + 1) can never run past the end of the string.
| Variable | Type | Purpose |
|---|---|---|
| s | String | the sentence, space added |
| pairs | int | count of double letters |
| w | String | the word being built |
| big | String | the longest word so far |
| ch | char | the current character |
| i | int | loop counter |
Enter a sentence in capitals: THE KEEPER ADDED THREE BALLOONS TO THE COFFEE TABLE Double letter pairs = 7 Longest word = BALLOONS (8 letters)
EE, DD, EE, LL, OO, FF and EE make seven. BALLOONS holds two pairs.
To put several of these into one program with a choice, see ICSE Class 10 menu driven programs; to sort an array of words alphabetically with compareTo, see bubble sort and selection sort for ICSE Class 10.
Q6. How are string programs taught in the live classes?
String programs are lost on small things: a missing space at the end, == instead of equals, an index one past the end. The live classes are arranged to catch those before the exam does.
At the Tuesday 5:30 PM IST class the mentor sets a fresh question from one family. Students write the whole program by hand, with the variable description table, in a fixed time.
The answers are marked in front of the group the way an examiner would: the loop, the method calls, the output format, the comments and the table each earn their share.
On Wednesday at 8:00 PM IST the same programs are typed and run with inputs chosen to break them: a sentence with double spaces, a word with no vowel, a Z at the end.
Each family ends with a worksheet of variations, and the next class opens with doubts from it, so nobody carries a confusion into the mock tests.
String questions then appear inside full two-hour papers alongside arrays, number programs and classes, timed and marked like the board.
These programs also make good entries for the lab file; how the internal assessment record is built is on ICSE Computer Applications project and internal assessment.
Batch or personalised: you choose
The six families, the cheat table and the BlueJ test runs are the same in both formats. In India, families can choose the fixed evening mini batch or a private slot; ICSE students abroad are taught one to one. Billing is monthly with no admission fee.
Option 1 · Fixed batch timings
₹2,999
per month, two live classes a week
Option 2 · Choose your own timing
₹4,999
per month, one private class a weektwo private classes a week, at a time set with you
Outside India: the ICSE Computer Applications course runs as personalised one to one, two private classes a week at a time set in your own time zone. The mini batch is taught for families in India.
A student who can write number programs but freezes when a sentence has to be broken into words often needs only a handful of one to one sessions on the extraction template. A student who wants regular practice across every Section B family is better served by the two batch classes each week. Fees appear in your own currency.
Studying outside India?
ICSE schools outside India sit the same Computer Applications paper, so the same string families decide the same Section B marks. Abroad, the practice runs one to one in an evening slot in the student's own time zone.
| Where you live | Time difference | Usual class window, local time | Format |
|---|---|---|---|
| India (IST) every Indian city | IST | Tue 5:30 PM, Wed 8:00 PM | Mini batch or 1-on-1 |
| United Arab Emirates Dubai, Sharjah | 1 h 30 min behind India | 3:00 PM to 9:00 PM | Personalised 1-on-1 |
| Indonesia and Thailand West Java, Bangkok area | 1 h 30 min ahead of India | 3:30 PM to 9:00 PM | Personalised 1-on-1 |
| Singapore Singapore | 2 h 30 min ahead of India | 3:30 PM to 9:00 PM | Personalised 1-on-1 |
The slot is fixed after the free demo and can move around school tests. Details for overseas families are on ICSE Computer Applications classes in the Gulf and abroad.
What families say
Real reviews from real families. We neither write nor commission them.
★★★★★
"The one step solution for my son. Modern Age Coders make learning coding so simple that kids love it. The teachers explain complex concepts clearly with practical exercises and interactive content."
Ria Mukherjee
Parent
★★★★★
"Modern Age Coders has been a game-changer for me. I struggled to grasp IT concepts and coding before joining, but their classes transformed everything. I can now confidently write complex programs with ease."
Samriddha Mondal
Student
★★★★★
"One of the most wonderful education centres out there. Education is not limited to school syllabus but focuses on skill development."
Vansh Agarwal
Student
★★★★★
"My child Dhairya is really enjoying the Modern Age Coders classes. This is his first online class and he eagerly looks forward to it. I can already see his improvement, and the teachers are very cooperative."
Sonam Oswal
Parent of Dhairya
★★★★★
"Modern Age Coders have wonderful teachers who teach in a clear, easy and practical way. The teacher boosts students' confidence and inspires them to learn without hesitation."
Sonu Goyal
Parent
★★★★★
"I highly recommend this computer coding class! The teachers are incredibly knowledgeable and passionate about coding."
Ritu Kedia
Parent
The rest of the Class 10 series
Every page in the ICSE Class 10 Computer Applications series, grouped by what you need: classes, each chapter, Section B programs, question practice, notes and revision, and the exam itself.
CBSE Class 10 AI (417): The Mon and Wed 9 PM AI batch CBSE AI 417 syllabus explained CBSE AI important questions Sample paper and mock tests
Questions about string programs
The families that keep returning are palindrome words, Pig Latin, frequency of letters or vowels, word handling such as capitalising each word or finding the longest word, coding by shifting letters, and double or consecutive letters. All of them use one loop over the string with charAt, so practise the loop until it is automatic.
Programs and output questions regularly use length, charAt, indexOf, lastIndexOf, substring, toLowerCase, toUpperCase, trim, replace, concat, equals, equalsIgnoreCase, compareTo, compareToIgnoreCase, startsWith, endsWith and String.valueOf. For each one, learn the return type as well as an example value, because output questions test both.
Build the reverse with a loop from length() minus 1 down to 0, adding each charAt to an empty String, then compare the original and the reverse with equals or equalsIgnoreCase. Do not use == for Strings. To find palindrome words in a sentence, run the same check on each word as it is extracted.
Find the index of the first vowel, then return substring(i) + substring(0, i) + "AY". Convert the word to capitals first so one vowel test works, and decide what to do with a word that has no vowel; the usual rule is to add AY to the whole word. Program 2 on this page does this for every word of a sentence.
Make an int array of 26 counters, convert the string to one case, and for every letter increase f[ch - 'A'] by one. After the loop, print each letter whose counter is above zero. For vowels only, five counters or a single test with indexOf on "AEIOU" is enough.
split runs in BlueJ, but it works with regular expressions, which are outside the Class 10 course, and you must be able to explain every line you write. It is safer to use the word-extraction template on this page: add one space to the end of the sentence and build each word character by character with charAt.
equals compares the characters inside two Strings; == checks whether two variables point to the very same object. Two Strings with identical letters can be different objects, so == may give false. In every ICSE string program, compare text with equals or equalsIgnoreCase.
Yes, whenever the question asks for one, and it is a good habit for every Section B answer. List each variable, its data type and its purpose in one line. It takes two minutes and shows the examiner you understand your own program.
Because a word is processed only when a space arrives, and there is no space after the last word. Add one space to the end of the sentence before the loop, as in s = s.trim() + " ", and the last word is closed like all the others.
Yes. In the mini batch on Tuesday and Wednesday evenings in India, students write a string program by hand, have it marked against the scheme on screen, then run it in BlueJ with awkward inputs. Families who need another time, or live abroad, can choose personalised one to one classes at their own time.
Start
In the free demo your child writes one sentence program from this page by hand, with its variable description table, then runs it in BlueJ with the mentor and fixes whatever the test input breaks. Afterwards you hear clearly which string families are secure and which need work, and whether the mini batch or one to one suits better.
Looking at the whole syllabus first? See ICSE Computer Applications important questions or the ICSE Class 10 Java classes.
WhatsApp us · +91 91233 66161 · connect@modernagecoders.com
Every class is live video. The form requests a callback and reserves nothing.
A full live class of about 45 to 60 minutes at a slot you pick, with a written skill report and learning roadmap on WhatsApp afterwards. The fee is adjusted against your first month if you enrol.
Book a priority demo