ISC Practical 2027: Sentence and Date (Vowels, Future Date, Sort by Length) – Algorithm and Java Program
Fully solved ISC Computer Science Practical 2027 blended question: validate a sentence and a date, count the vowels, add that many days to the date (handling month, year and leap-year changes) and sort the words by length while keeping the original order for ties.

This is Question 3 of Sample Paper 4 from the specimen questions CISCE has released for the ISC Year 2027 Computer Science Practical (Paper 2). The concept area is Blended concepts: string + date. Below you will find the question, a plain-language explanation of the logic, an exam-ready algorithm, a fully documented Java program, the real output for every sample input, and tips for scoring the full 15 marks.
Every program on this page was compiled with JDK 21 and run on CISCE’s sample inputs, plus extra boundary inputs of the kind a visiting examiner will try.
The question
Write a program that accepts (a) a sentence terminated by ".", "?" or "!" and (b) a date in the format DD/MM/YYYY. Assume that the words in the sentence are separated by a single blank space. The program should:
- Validate the date and the sentence, and display an appropriate error message if either is invalid.
- Count and display the total number of vowels (V) in the sentence.
- Add V days to the given date and display the resulting future date.
- Sort the words in ascending order of length. For words of equal length, keep their original order of appearance. Display the sorted words.
CISCE gives 3 examples with this question. Each one is shown with its output in the Output section below, so you can check your own program against it.
Understanding the problem
This question blends string handling with the date concept, which makes it the longest of the twelve. Break it into small methods and it becomes manageable.
- Adding days safely: move forward one day at a time. When the day passes the end of the month, reset it to 1 and move to the next month; after December, move to January of the next year. This automatically handles 29 February and year changes.
- Stable sorting: "keep the original order for equal lengths" means the sort must be *stable*. Insertion sort (shift while the previous word is strictly longer) and bubble sort (swap only when strictly longer) are both stable. Selection sort is not, so avoid it here.
- Vowels: count A, E, I, O and U in both cases. "y" is not a vowel. Example 1 confirms this: "today" contributes only o and a.
- Print two-digit day and month (09/03/2024), as in the sample output.

Algorithm [3 marks]
Write the algorithm in the planning session, in numbered steps like these. It must match your program exactly.
- Start.
- Input the sentence and the date.
- Validate the sentence: it must end with ".", "?" or "!", and the rest must contain only letters separated by single spaces. If not, print "INVALID SENTENCE" and stop.
- Validate the date: pattern DD/MM/YYYY, month 1 to 12, day 1 to the days in that month (29 for February in a leap year). If not, print "INVALID DATE" and stop.
- Split the sentence (without its last character) into words[].
- V = number of characters in the sentence that are vowels (both cases). Print V.
- Repeat V times: increase dd. If dd exceeds the days in month mm, set dd = 1 and increase mm; if mm exceeds 12, set mm = 1 and increase yy.
- Print the future date as DD/MM/YYYY with two-digit day and month.
- Insertion sort words[] by length: for i = 1 to n − 1, take key = words[i] and shift each earlier word that is strictly longer one place right, then insert key.
- Print the sorted words.
- Stop.
Java program [7 marks]
The program uses a class with separate methods for each task and comments that explain every data member and the special logic. That is what the 2 documentation marks are for.
import java.util.Scanner;
/**
* ISC Practical 2027 - Sample Paper 4, Question 3
* Counts the vowels (V) in a sentence, adds V days to a date and
* sorts the words by length, keeping the original order for equal lengths.
*/
public class SentenceDate
{
String sent; // sentence ending with . ? or !
String words[]; // words of the sentence
int dd, mm, yy; // the date
boolean isLeap(int y)
{
return (y % 4 == 0 && y % 100 != 0) || y % 400 == 0;
}
int daysInMonth(int m, int y)
{
int days[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
return (m == 2 && isLeap(y)) ? 29 : days[m - 1];
}
// ends with . ? or ! and the words contain only letters, separated by single spaces
boolean validSentence(String s)
{
sent = s.trim();
int len = sent.length();
if (len < 2)
return false;
char last = sent.charAt(len - 1);
if (last != '.' && last != '?' && last != '!')
return false;
String body = sent.substring(0, len - 1);
if (body.startsWith(" ") || body.endsWith(" ") || body.indexOf(" ") >= 0)
return false;
for (int i = 0; i < body.length(); i++)
if (!Character.isLetter(body.charAt(i)) && body.charAt(i) != ' ')
return false;
words = body.split(" ");
return true;
}
boolean validDate(String d)
{
d = d.trim();
if (d.length() != 10 || d.charAt(2) != '/' || d.charAt(5) != '/')
return false;
for (int i = 0; i < 10; i++)
if (i != 2 && i != 5 && !Character.isDigit(d.charAt(i)))
return false;
dd = Integer.parseInt(d.substring(0, 2));
mm = Integer.parseInt(d.substring(3, 5));
yy = Integer.parseInt(d.substring(6));
return mm >= 1 && mm <= 12 && yy >= 1 && dd >= 1 && dd <= daysInMonth(mm, yy);
}
int countVowels()
{
int v = 0;
for (int i = 0; i < sent.length(); i++)
if ("AEIOUaeiou".indexOf(sent.charAt(i)) >= 0)
v++;
return v;
}
// moves the date forward by n days, one day at a time
void addDays(int n)
{
for (int k = 1; k <= n; k++)
{
dd++;
if (dd > daysInMonth(mm, yy))
{
dd = 1;
mm++;
if (mm > 12)
{
mm = 1;
yy++;
}
}
}
}
// insertion sort on word length: stable, so equal lengths keep their order
void sortWords()
{
for (int i = 1; i < words.length; i++)
{
String key = words[i];
int j = i - 1;
while (j >= 0 && words[j].length() > key.length())
{
words[j + 1] = words[j];
j--;
}
words[j + 1] = key;
}
}
String two(int x)
{
return (x < 10 ? "0" : "") + x;
}
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
SentenceDate ob = new SentenceDate();
System.out.print("Sentence: ");
String s = sc.nextLine();
System.out.print("Date: ");
String d = sc.nextLine();
if (!ob.validSentence(s))
{
System.out.println("INVALID SENTENCE");
return;
}
if (!ob.validDate(d))
{
System.out.println("INVALID DATE");
return;
}
int v = ob.countVowels();
ob.addDays(v);
System.out.println("NUMBER OF VOWELS = " + v);
System.out.println("FUTURE DATE (AFTER " + v + " DAYS): "
+ ob.two(ob.dd) + "/" + ob.two(ob.mm) + "/" + ob.yy);
ob.sortWords();
System.out.println("SORTED WORDS BY LENGTH:");
String out = "";
for (int i = 0; i < ob.words.length; i++)
out += ob.words[i] + " ";
System.out.println(" " + out.trim());
}
}Variable description
Name Type Purpose
------------- --------- -------
sent String sentence entered by the user
words[] String[] words of the sentence
dd, mm, yy int the date, moved forward by V days
v int number of vowels
key String word being inserted during the sort
i, j int loop indexes for the insertion sortOutput [3 marks]
These are the actual outputs of the program above for every example in the question:
INPUT:
Sentence: The sun is bright today.
Date: 20/01/2024
OUTPUT:
NUMBER OF VOWELS = 6
FUTURE DATE (AFTER 6 DAYS): 26/01/2024
SORTED WORDS BY LENGTH:
is The sun today brightINPUT:
Sentence: AI is amazing and useful?
Date: 28/02/2024
OUTPUT:
NUMBER OF VOWELS = 10
FUTURE DATE (AFTER 10 DAYS): 09/03/2024
SORTED WORDS BY LENGTH:
AI is and useful amazingINPUT:
Sentence: Good Morning everyone.
Date: 31/04/2024
OUTPUT:
INVALID DATETest it on unknown inputs
One of the 3 output marks is for correct output on inputs the examiner chooses, usually boundary cases. Our program handles these correctly:
INPUT:
Sentence: Happy new year everyone!
Date: 28/12/2025
OUTPUT:
NUMBER OF VOWELS = 8
FUTURE DATE (AFTER 8 DAYS): 05/01/2026
SORTED WORDS BY LENGTH:
new year Happy everyoneINPUT:
Sentence: Practice every day
Date: 10/10/2026
OUTPUT:
INVALID SENTENCEHow to score full marks on this question

- Name the sort in your algorithm ("insertion sort, stable") and explain why stability matters here. That reasoning earns the "choice of algorithm" mark.
- Run the second example: it crosses 29 February 2024, which proves your leap-year handling.
- Use clear separate error messages (INVALID SENTENCE, INVALID DATE). The question asks for "an appropriate error message".
- Keep the typed program identical to the planned one. Large differences between your planning sheet and the printout cost the 2 hard-copy marks.
Common mistakes to avoid
- Adding V to the day directly (28 + 10 = 38) without moving to the next month.
- Using a selection sort, which can change the order of equal-length words.
- Counting "y" as a vowel, or forgetting uppercase vowels such as the A and I in "AI".
This post is part of our series that solves all 12 specimen questions for the ISC 2027 Computer Science practical, one question a day. Practise writing the algorithm and program on paper in 90 minutes before you type it. That is exactly how the exam works.
Related Posts
Continue learning with these related articles

Karnaugh Maps (K-Maps) for ISC Class 12: SOP and POS Reduction Step by Step
A complete ISC Class 12 Computer Science guide to Karnaugh maps: cell numbering for 3- and 4-variable maps, grouping rules, SOP and POS reduction with fully solved examples, and the mistakes that cost marks in the board exam.

ISC Practical 2027: Special Date Checker (Validation and Digit Sum) – Algorithm and Java Program
Fully solved ISC Computer Science Practical 2027 date question: validate a date in DD/MM/YYYY format including leap years, find the days remaining in the month and check whether its digit sum is a perfect square.

ISC Practical 2027: Local Minimum Cells in a Matrix – Algorithm and Java Program
Fully solved ISC Computer Science Practical 2027 matrix question: in an elevation matrix of order M × N, find every Local Minimum Cell (an interior cell strictly lower than its four neighbours) and the smallest one.