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.

This is Question 2 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 Date concept + number logic. 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 to accept a date in the format DD/MM/YYYY. Validate the date, considering the correct number of days in each month and the leap year rules. If the date is invalid, display INVALID DATE. If it is valid:
- Display the number of days remaining in that month.
- Find the sum of all the digits of DD, MM and YYYY.
- If the digit sum is a perfect square, display
SPECIAL DATE; otherwise displayREGULAR DATE.
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
A date validation question blended with simple number logic. Almost every ISC practical paper has a date question, so a reliable validation method is worth practising until you can write it from memory.
- Check the pattern first: length 10, "/" at index 2 and 5, and digits everywhere else. Only then use
Integer.parseInt(), otherwise "5/8/2023" or letters would crash the program. - Then check the ranges: month 1 to 12, and day 1 to the number of days in that month, with February having 29 days in a leap year.
- Leap year rule: divisible by 4 and not by 100, or divisible by 400. So 2000 is a leap year but 1900 is not.
- Perfect square:
int r = (int) Math.sqrt(sum); if (r * r == sum). Comparing integers avoids floating-point surprises.

Algorithm [3 marks]
Write the algorithm in the planning session, in numbered steps like these. It must match your program exactly.
- Start.
- Input the date as a String s.
- If the length of s is not 10, s[2] or s[5] is not "/", or any other character is not a digit, print "INVALID DATE" and stop.
- dd = s.substring(0, 2), mm = s.substring(3, 5) and yy = s.substring(6), converted to integers.
- If mm < 1 or mm > 12, or dd < 1 or dd > days in month mm of year yy (29 for February in a leap year), print "INVALID DATE" and stop.
- remaining = days in the month − dd. Print it.
- sum = sum of all 8 digits in s. Print it.
- r = integer square root of sum. If r × r == sum, print "SPECIAL DATE", otherwise print "REGULAR DATE".
- 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 2
* Validates a date in DD/MM/YYYY format, finds the days remaining in the month
* and checks whether the sum of its digits is a perfect square.
*/
public class SpecialDate
{
String date; // date as entered, DD/MM/YYYY
int dd, mm, yy; // day, month and year
SpecialDate(String s)
{
date = s.trim();
}
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};
if (m == 2 && isLeap(y))
return 29;
return days[m - 1];
}
// checks the DD/MM/YYYY pattern, then the month and the day range
boolean isValid()
{
if (date.length() != 10 || date.charAt(2) != '/' || date.charAt(5) != '/')
return false;
for (int i = 0; i < 10; i++)
if (i != 2 && i != 5 && !Character.isDigit(date.charAt(i)))
return false;
dd = Integer.parseInt(date.substring(0, 2));
mm = Integer.parseInt(date.substring(3, 5));
yy = Integer.parseInt(date.substring(6));
if (mm < 1 || mm > 12 || yy < 1)
return false;
return dd >= 1 && dd <= daysInMonth(mm, yy);
}
void process()
{
if (!isValid())
{
System.out.println("INVALID DATE");
return;
}
int remaining = daysInMonth(mm, yy) - dd;
int sum = 0;
for (int i = 0; i < date.length(); i++) // adds every digit of DD, MM and YYYY
if (Character.isDigit(date.charAt(i)))
sum += date.charAt(i) - '0';
int root = (int) Math.sqrt(sum);
System.out.println("DAYS REMAINING: " + remaining);
System.out.println("DIGIT SUM = " + sum);
if (root * root == sum)
System.out.println("SPECIAL DATE");
else
System.out.println("REGULAR DATE");
}
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter the date (DD/MM/YYYY): ");
SpecialDate ob = new SpecialDate(sc.nextLine());
ob.process();
}
}Variable description
Name Type Purpose
------------- --------- -------
date String date entered as DD/MM/YYYY
dd, mm, yy int day, month and year
remaining int days left in the month after dd
sum int sum of the digits of the date
root int integer square root of sumOutput [3 marks]
These are the actual outputs of the program above for every example in the question:
INPUT:
15/08/2023
OUTPUT:
DAYS REMAINING: 16
DIGIT SUM = 21
REGULAR DATEINPUT:
13/03/2000
OUTPUT:
DAYS REMAINING: 18
DIGIT SUM = 9
SPECIAL DATEINPUT:
30/02/2023
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:
29/02/2024
OUTPUT:
DAYS REMAINING: 0
DIGIT SUM = 21
REGULAR DATEINPUT:
29/02/1900
OUTPUT:
INVALID DATEINPUT:
31/12/2025
OUTPUT:
DAYS REMAINING: 0
DIGIT SUM = 16
SPECIAL DATEINPUT:
5/8/2023
OUTPUT:
INVALID DATEHow to score full marks on this question

- Write isLeap(), daysInMonth() and isValid() as separate methods. You can reuse them in any date question in the exam.
- Test 29/02/2024 (valid), 29/02/1900 (invalid) and 31/04/2024 (invalid). These are the classic boundary cases examiners use.
- The digit sum adds all eight digits, including zeros: 13/03/2000 gives 1+3+0+3+2+0+0+0 = 9.
- 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
- Calling parseInt() before checking the format, which throws NumberFormatException on bad input.
- Using the simple "divisible by 4" rule for leap years.
- Treating 1 as the only perfect square check, or using Math.sqrt(sum) % 1 == 0 with doubles.
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

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.

ISC Class 12 Recursion Programs: 8 Solved Questions for Theory and Practical
Master recursion for ISC Class 12 Computer Science with 8 solved Java programs: factorial, power, GCD, palindrome check, decimal to binary, Fibonacci, string reversal and recursive binary search, plus tips on tracing output questions.

ISC Practical 2027: Ticket Date Analyzer (Day Number, Gaps and Fare Type) – Algorithm and Java Program
Fully solved ISC Computer Science Practical 2027 date question: convert booking, travel and return dates to day numbers of the year, validate their order, find the booking gap and trip duration, and decide the fare type.