ISC Practical 2027: River Basin Rainfall and Flood Warning – Algorithm and Java Program
Fully solved ISC Computer Science Practical 2027 question: validate a basin code (RB followed by 4 digits), find the digit sum of the basin number and analyse N days of rainfall to decide whether to raise a flood warning.

This is Question 2 of Sample Paper 2 from the specimen questions CISCE has released for the ISC Year 2027 Computer Science Practical (Paper 2). The concept area is Blended concepts: string + number + array. 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
A river basin monitoring system assigns each basin a unique code in the format RB followed by a 4-digit numeric identifier (for example, RB4319). Write a program to accept a basin code and rainfall readings for N days, where 5 ≤ N ≤ 20. If the code is not in the correct format, or N is outside the range, display an appropriate error message.
- Extract the basin number from the basin code.
- Calculate the sum of all digits in the basin number.
- Store the rainfall readings and display the highest, lowest and average rainfall.
- Count the number of days on which the rainfall exceeds 150 mm.
- If the average rainfall is greater than 150 mm, display
FLOOD WARNING GENERATED; otherwise displayNORMAL CONDITIONS.
CISCE gives 5 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 a string check, number logic and a one-dimensional array. Each part is simple. The marks come from doing them in the right order and formatting the output exactly.
- Validate the code before asking for N. Example 4 stops immediately after an invalid code. The code must be exactly 6 characters: "RB" + 4 digits. "rb4319" and "RB43190" are invalid.
- Extract the number with
substring(2), then convert it withInteger.parseInt()to find the digit sum using% 10and/ 10. - One pass over the array can find the maximum, minimum, sum and the count of readings above 150.
- Two decimal places: the average is printed as 161.67 and 140.00, so use
String.format("%.2f", avg). - "Greater than 150" is strict. An average of exactly 150 means NORMAL CONDITIONS.

Algorithm [3 marks]
Write the algorithm in the planning session, in numbered steps like these. It must match your program exactly.
- Start.
- Input the basin code. If its length is not 6, it does not start with "RB", or characters 3 to 6 are not all digits, print "Invalid Basin Code" and stop.
- Input N. If N < 5 or N > 20, print "Invalid Number of Days" and stop.
- Input N readings into rain[].
- Set basinNo = integer value of code.substring(2). Find digitSum by repeatedly adding basinNo % 10 and dividing basinNo by 10.
- Set max = min = rain[0], sum = 0, heavy = 0. For each reading: update max and min, add it to sum, and if it is greater than 150 increase heavy.
- avg = sum / N (real division).
- Print the basin number, digit sum, max, min, avg to 2 decimal places and heavy.
- If avg > 150, print "FLOOD WARNING GENERATED", otherwise print "NORMAL CONDITIONS".
- 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 2, Question 2
* Validates a river basin code (RB + 4 digits) and analyses rainfall
* readings for N days (5 to 20).
*/
public class RiverBasin
{
String code; // basin code, for example RB4319
int rain[]; // rainfall readings in mm
int n; // number of days
RiverBasin(String c)
{
code = c.trim();
}
// "RB" followed by exactly 4 digits
boolean isValidCode()
{
if (code.length() != 6 || !code.startsWith("RB"))
return false;
for (int i = 2; i < 6; i++)
if (!Character.isDigit(code.charAt(i)))
return false;
return true;
}
int digitSum(int num)
{
int s = 0;
while (num > 0)
{
s += num % 10;
num /= 10;
}
return s;
}
void acceptReadings(Scanner sc, int days)
{
n = days;
rain = new int[n];
System.out.println("Enter " + n + " rainfall readings:");
for (int i = 0; i < n; i++)
rain[i] = sc.nextInt();
}
void analyse()
{
int basinNo = Integer.parseInt(code.substring(2)); // numeric part of the code
int max = rain[0], min = rain[0], sum = 0, heavy = 0;
for (int i = 0; i < n; i++)
{
if (rain[i] > max) max = rain[i];
if (rain[i] < min) min = rain[i];
sum += rain[i];
if (rain[i] > 150) heavy++;
}
double avg = (double) sum / n;
System.out.println("Basin Number: " + code.substring(2));
System.out.println("Digit Sum: " + digitSum(basinNo));
System.out.println("Highest Rainfall: " + max);
System.out.println("Lowest Rainfall: " + min);
System.out.println("Average Rainfall: " + String.format("%.2f", avg));
System.out.println("Days exceeding 150 mm: " + heavy);
if (avg > 150)
System.out.println("FLOOD WARNING GENERATED");
else
System.out.println("NORMAL CONDITIONS");
}
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
System.out.print("Basin Code: ");
RiverBasin ob = new RiverBasin(sc.next());
if (!ob.isValidCode())
{
System.out.println("Invalid Basin Code");
return;
}
System.out.print("N: ");
int days = sc.nextInt();
if (days < 5 || days > 20)
{
System.out.println("Invalid Number of Days");
return;
}
ob.acceptReadings(sc, days);
ob.analyse();
}
}Variable description
Name Type Purpose
------------- --------- -------
code String basin code, for example RB4319
rain[] int[] rainfall readings in mm
n int number of days
basinNo int numeric part of the code
max, min int highest and lowest rainfall
sum int total rainfall
heavy int days with rainfall above 150 mm
avg double average rainfallOutput [3 marks]
These are the actual outputs of the program above for every example in the question:
INPUT:
Basin Code: RB4319
N: 6
180 145 170 155 190 130
OUTPUT:
Basin Number: 4319
Digit Sum: 17
Highest Rainfall: 190
Lowest Rainfall: 130
Average Rainfall: 161.67
Days exceeding 150 mm: 4
FLOOD WARNING GENERATEDINPUT:
Basin Code: RB5824
N: 5
120 135 140 160 145
OUTPUT:
Basin Number: 5824
Digit Sum: 19
Highest Rainfall: 160
Lowest Rainfall: 120
Average Rainfall: 140.00
Days exceeding 150 mm: 1
NORMAL CONDITIONSINPUT:
Basin Code: RB7608
N: 7
210 185 160 175 220 195 180
OUTPUT:
Basin Number: 7608
Digit Sum: 21
Highest Rainfall: 220
Lowest Rainfall: 160
Average Rainfall: 189.29
Days exceeding 150 mm: 7
FLOOD WARNING GENERATEDINPUT:
Basin Code: R4319
OUTPUT:
Invalid Basin CodeINPUT:
Basin Code: RB4319
N: 3
OUTPUT:
Invalid Number of DaysTest 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:
Basin Code: RB0150
N: 5
150 150 150 150 150
OUTPUT:
Basin Number: 0150
Digit Sum: 6
Highest Rainfall: 150
Lowest Rainfall: 150
Average Rainfall: 150.00
Days exceeding 150 mm: 0
NORMAL CONDITIONSINPUT:
Basin Code: rb4319
OUTPUT:
Invalid Basin CodeINPUT:
Basin Code: RB43190
OUTPUT:
Invalid Basin CodeHow to score full marks on this question

- Print the basin number as the substring ("0150"), not the parsed int (150), so leading zeros are not lost.
- Use the exact messages from the question ("Invalid Basin Code", "Invalid Number of Days"). They are part of the expected output.
- Show a boundary test with an average of exactly 150. It proves you used > and not >=.
- 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
- Printing the average without formatting (161.66666666666666).
- Initialising max to 0 and min to 0. min would then never change. Start both with rain[0].
- Accepting "RB43" or "RB12345" because only startsWith("RB") was checked.
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: Phishing Message Detector and Encryption – Algorithm and Java Program
Fully solved ISC Computer Science Practical 2027 string question: validate a sentence, extract words, count phishing keywords, classify the message as SAFE, SUSPICIOUS or PHISHING ALERT and encrypt it by reversing the keywords.

7 ISC Practical Programs with Solutions: Circular Prime, Prime-Adam and More
Seven ISC Computer Science practical exam programs with Java solutions: circular prime, consecutive number combinations, Prime-Adam numbers, two matrix programs and two sentence-processing programs. Free PDF with a step-by-step dry run.

ISC Class 12 Computer Science MCQ Practice Tests (Boolean Algebra & Java)
Five ISC Class 12 Computer Science MCQ practice tests on Boolean algebra, propositional logic, hardware, K-maps, array address calculation and Java output questions, two of them with answer keys. Free PDF download with solved examples.