ICSE Class 10 · Computer Applications (Java) · String programs 2027

ICSE Class 10 string programs, written the way the board marks them.

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

Courses where string programs are taught

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.

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?

String handling ICSE: the six program families

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.

FamilyWhat the question asksThe key ideaProgram below
PalindromeCheck a word, or print every palindrome word in a sentenceBuild the reverse with a backward loop, compare with equalsProgram 1
Pig LatinMove the letters before the first vowel to the end and add AYindexOf on "AEIOU" finds a vowel; two substrings rebuild the wordProgram 2
FrequencyCount each letter, vowel or character in a stringAn int array of 26 counters, indexed by ch minus 'A'Program 3
Word handlingCapitalise each word, count words, find words with a propertyA word starts where the character before it is a spaceProgram 4
CodingShift each letter a fixed number of places, keep other charactersCharacter arithmetic with % 26 so Z wraps round to AProgram 5
Pairs and lengthsDouble letters, consecutive letters, the longest wordCompare charAt(i) with charAt(i + 1) inside the boundsProgram 6

The word-extraction template

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:

  1. Read the sentence with nextLine(), then trim() it and add " " at the end.
  2. Loop over every index. If the character is not a space, add it to w.
  3. When a space arrives and w is not empty, the word is complete: process it.
  4. Set 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?

String functions ICSE: a cheat table with real return values

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.

MethodReturnsExampleResult
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 / equalsIgnoreCaseboolean"Java".equals("JAVA"), "Java".equalsIgnoreCase("JAVA")false, true
compareTo(String)int"APPLE".compareTo("ANT")2
compareToIgnoreCase(String)int"apple".compareToIgnoreCase("APPLE")0
startsWith / endsWithboolean"ICSE".startsWith("IC"), "BlueJ".endsWith("j")true, false
String.valueOfStringString.valueOf(45) + 5455

substring(3, 6) stops before 6

The end index is excluded, so the result has 6 minus 3, that is three, characters. The commonest slip in the whole table.

compareTo returns a difference

"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.

Results must be stored

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?

Palindrome word program in Java ICSE, and the Pig Latin program

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.

Program 1: print and count the palindrome words in a sentence

PalinWords.javapalindrome words
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.

VariableTypePurpose
sStringthe sentence, with one space added at the end
wStringthe word being built
revStringw written backwards
chcharthe current character
countintnumber of palindrome words
i, jintloop counters
Sample runJava 21
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.

Program 2: Pig Latin for every word of a sentence

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.

PigLatinLine.javaPig Latin program
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.

VariableTypePurpose
w (in pig)Stringone word in capitals
sStringthe sentence in capitals, space added
w (in main)Stringthe word being built
outStringthe converted sentence
chcharthe current character
iintloop counter
Sample runJava 21
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?

Frequency of characters in Java ICSE, and word-by-word programs

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.

Program 3: frequency of every letter in a string

LetterFreq.javaarray of counters
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.

VariableTypePurpose
sStringthe input in capitals
fint[]26 counters, one per letter
chcharthe current character
i, kintloop counters
Sample runJava 21
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.

Program 4: capitalise each word and count words that begin with a vowel

TitleVowel.javafirst letter of each word
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.

VariableTypePurpose
sStringthe sentence in small letters
outStringthe sentence with capitals added
chcharthe current character
firstbooleantrue when ch starts a word
vintwords beginning with a vowel
iintloop counter
Sample runJava 21
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?

ICSE string programs on letter shifts, double letters and the longest word

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.

Program 5: code a message by shifting each letter two places

ShiftCode.javacoding with wrap-round
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.

VariableTypePurpose
sStringthe original message
codeStringthe coded message
chcharthe current character, then its coded form
iintloop counter
Sample runJava 21
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.

Program 6: count double letters and find the longest word

DoubleLetters.javapairs and lengths
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.

VariableTypePurpose
sStringthe sentence, space added
pairsintcount of double letters
wStringthe word being built
bigStringthe longest word so far
chcharthe current character
iintloop counter
Sample runJava 21
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?

From a blank page to a marked string program

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.

  1. One family per week, on paper first

    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.

  2. Marked against the scheme on screen

    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.

  3. Run in BlueJ with awkward input

    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.

  4. Worksheets and doubt time

    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.

  5. Mock papers from December

    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

Practise string programs in the mini batch, or one to one

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

Mini batch, Tuesday 5:30 PM and Wednesday 8 PM

₹2,999

per month, two live classes a week

  • Tuesday 5:30 PM and Wednesday 8:00 PM IST, live
  • At most six ICSE Class 10 students
  • A string program written by hand each fortnight
  • Answers marked against the scheme on screen
  • Programs tested in BlueJ with awkward input
Book a free demo in this batch

Option 2 · Choose your own timing

Personalised one to one

₹4,999

per month, one private class a week, at a time set with you

  • A time the family picks, in India or abroad
  • Extra time on the family your child finds hardest
  • Variable description tables written together
  • Harder sentence programs once the basics hold
  • The same mentors and the same 2027 syllabus
Ask for a personalised plan

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?

String program practice for ICSE students abroad

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 liveTime differenceUsual class window, local timeFormat
India (IST)
every Indian city
ISTTue 5:30 PM, Wed 8:00 PMMini batch or 1-on-1
United Arab Emirates
Dubai, Sharjah
1 h 30 min behind India3:00 PM to 9:00 PMPersonalised 1-on-1
Indonesia and Thailand
West Java, Bangkok area
1 h 30 min ahead of India3:30 PM to 9:00 PMPersonalised 1-on-1
Singapore
Singapore
2 h 30 min ahead of India3:30 PM to 9:00 PMPersonalised 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

Rated 4.9 across 547 Google reviews

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

More pages for Class 10 board students

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

What students ask about ICSE Class 10 string programs

What are the important string programs for ICSE Class 10?

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.

Which String functions are in the ICSE Class 10 syllabus?

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.

How do you check if a word is a palindrome in Java ICSE?

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.

How do you write a Pig Latin program in ICSE?

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.

How do you count the frequency of each character in Java?

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.

Can I use split() in ICSE string programs?

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.

What is the difference between == and equals for Strings?

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.

Do I need a variable description table for string programs?

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.

Why does my string program skip the last word?

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.

Do you teach ICSE string programs in live classes?

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

Book a free live string handling class

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.

We call within a few hours. No card, no enrolment fee.

Want it sooner? Book a priority demo

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

Keep exploring Modern Age Coders

By class and age

Learn more

Free resources

From the blog

Start here