Implementation of Algorithms to Solve Problems: ISC Class 12 Computer Science
Updated 15 October 2026 · Fact-checked
Solving a problem in ISC Computer Science means designing a correct algorithm, turning it into a Java class with the data members and methods the question specifies, testing it with dry runs and sample data, and debugging it. Section B of Paper 1 asks you to write two such complete programs, each worth 10 marks.
What Implementation of Algorithms to Solve Problems is about
This sub-topic is described in the syllabus as self-explanatory: students must do algorithm design, address correctness issues, implement and execute the algorithm in Java and debug where necessary, with lab assignments covering every major topic.
In the examination this skill is tested in Part II, Section B (answer two of three 10-mark questions). Each question gives a class description: class name, data members, and methods with their purpose. You must specify the class in Java, giving the constructor and the named methods, and write a main( ) method that creates an object and calls the methods. Flowcharts and algorithms are not required there, but the program must show the logic clearly through mnemonic names and comments.
The same skills appear in Part I, Question 2: tracing (dry-running) a given method and filling in missing expressions (?1?, ?2?, ?3?).
The practical paper (Paper 2, 30 marks) also asks you to write an algorithm, then the program with documentation, and to test it with output.
All programs on this page were compiled and run, and their outputs are shown exactly as produced.
Weightage: CISCE publishes no chapter or unit weightage for ISC Computer Science. Implementation of Algorithms to Solve Problems is part of Section B, 3 of the 2027 syllabus and can be asked anywhere in the 70-mark Paper 1 (Part I compulsory: ten 1-mark items and a 10-mark short-answer question; Part II: two of three 10-mark questions in each of Sections A and B, and two of three 5-mark questions in Section C).Source: CISCE ISC Computer Science (868) syllabus, examination year 2027; latest Paper 1 specimen (2025) and the 2025 board paper
Key concepts
- From problem to algorithm
An algorithm is a finite sequence of clear, unambiguous steps that solves a problem for every valid input and stops.
Properties: finiteness (it ends), definiteness (each step is precise), input (zero or more), output (at least one), effectiveness (each step can be carried out).
Steps for designing one:
1. Understand the problem: identify inputs, outputs and the rule connecting them; work two or three examples by hand, including edge cases (0, 1, negative, single digit, empty string).
2. Break it into sub-tasks, each becoming a method (for example accept, isPrime, reverse, check).
3. Write the steps in structured English or pseudocode with sequence, selection and iteration (or recursion).
4. Check correctness on the hand-worked examples (a dry run).
5. Only then write the Java code.Example (GCD by Euclid's algorithm):
Step 1: Read a, b.
Step 2: While b is not 0: r = a mod b; a = b; b = r.
Step 3: Output a (the GCD). LCM = a original × b original / GCD.
It is correct because GCD(a, b) = GCD(b, a mod b), and b strictly decreases, so the loop ends.Worked example
[2] Write an algorithm to find the GCD of two positive integers by Euclid's method and state why it always stops. (Create)
Try it first, then show the solutionSolution
- Steps: read a, b; while b ≠ 0 do r = a % b, a = b, b = r; print a - 1 mark.
- It stops because the remainder is always smaller than b, so b decreases each time and must reach 0 - 1 mark.
Answer: Read a and b; while b is not zero, set r = a % b, a = b, b = r; when b becomes zero, a is the GCD. The loop must end because each new b (the remainder) is smaller than the previous b and cannot go below zero.
- Dry runs and tracing
A dry run executes the algorithm by hand, recording the values of variables after each step in a trace table. It is the main tool for checking correctness and for answering 'find the output' questions.
Trace of the GCD loop for a = 84, b = 36 (program GcdTrace below):
a b a % b 84 36 12 36 12 0 Result: GCD = 12, LCM = 84 / 12 × 36 = 252.
// Euclid's algorithm with a printed trace, and LCM from GCD. public class GcdTrace { static int gcd(int a, int b) { while (b != 0) { System.out.println("a = " + a + ", b = " + b + ", a % b = " + (a % b)); int r = a % b; a = b; b = r; } return a; } public static void main(String[] args) { int x = 84, y = 36; int g = gcd(x, y); System.out.println("GCD = " + g); System.out.println("LCM = " + (x / g * y)); } }Output:
a = 84, b = 36, a % b = 12 a = 36, b = 12, a % b = 0 GCD = 12 LCM = 252Tips for tracing questions:
1. Make one column per variable and one row per iteration or call.
2. Update variables in the order the statements execute.
3. For recursion, write each call on a new line and then unwind the returns in reverse order.
4. State the final answer and, if asked, what the method does in general (its purpose).Worked example
[2] Trace the GCD loop for a = 45, b = 20 and give the GCD and LCM. (Apply)
Try it first, then show the solutionSolution
- 45 % 20 = 5 → a = 20, b = 5; 20 % 5 = 0 → a = 5, b = 0 - 1 mark.
- GCD = 5; LCM = 45 / 5 × 20 = 180 - 1 mark.
Answer: GCD = 5 and LCM = 180.
- Correctness and test data
A program is correct if it produces the right output for every valid input. To check:
1. Normal cases: typical values (13, 4075).
2. Boundary cases: smallest and largest valid values (0, 1, single-digit numbers, an array of one element, an empty string).
3. Special cases suggested by the definition (for an Emirp number, a palindromic prime such as 11 must be rejected because its reverse is not a different prime).
4. Invalid input handling if the question asks for it (for example 'display an appropriate message if the input is out of range').Loop correctness: check the loop condition, the initial value and the update. Most errors are off-by-one errors (one iteration too many or too few) or a missing update that makes a loop infinite.
Recursion correctness: there must be a base case that stops the recursion, and each recursive call must move towards it.
Worked example
[2] Suggest four test values for a method that checks whether a number is an Emirp, and say why each is useful. (Evaluate)
Try it first, then show the solutionSolution
- 13 and 97: normal Emirps (reverse 31 and 79 are prime); 23: prime whose reverse 32 is not prime - 1 mark.
- 11: palindromic prime (reverse is the same number, so not an Emirp); 1: not prime (boundary) - 1 mark.
Answer: 13 (Emirp), 23 (prime but reverse not prime), 11 (palindromic prime, rejected) and 1 (not prime, a boundary case) together test every branch of the condition.
- Debugging: syntax, run-time and logical errors
Types of error:
1. Syntax (compile-time) errors: break the rules of Java, so the compiler rejects the program: missing semicolon, unmatched braces, misspelt keyword, using an undeclared variable, type mismatch (int x = 2.5;).
2. Run-time errors (exceptions): the program compiles but fails while running: division by zero (ArithmeticException), array index out of bounds (ArrayIndexOutOfBoundsException), calling a method on null (NullPointerException), wrong input type (InputMismatchException).
3. Logical errors: the program runs but gives wrong results because the algorithm or code is wrong, such as a wrong loop condition. These are found only by testing and dry runs.Example of a logical error: summing digits with while (n > 9) stops before the last digit.
// Intended: sum of the digits of n. The corrected loop is in sumDigits; the buggy one is shown for comparison. public class BuggySum { static int buggy(int n) { int s = 0; while (n > 9) // bug: stops before the last digit { s = s + n % 10; n = n / 10; } return s; } static int sumDigits(int n) { int s = 0; while (n > 0) // correct: runs until every digit is used { s = s + n % 10; n = n / 10; } return s; } public static void main(String[] args) { System.out.println("buggy(4075) = " + buggy(4075)); System.out.println("sumDigits(4075) = " + sumDigits(4075)); System.out.println("sumDigits(7) = " + sumDigits(7)); System.out.println("sumDigits(0) = " + sumDigits(0)); } }Output:
buggy(4075) = 12 sumDigits(4075) = 16 sumDigits(7) = 7 sumDigits(0) = 0The buggy version returns 12 for 4075 because it never adds the leading digit 4; the correct condition n > 0 gives 16.
Debugging techniques: dry runs; printing intermediate values; testing small cases; checking boundary values; using the BlueJ debugger to step through code and inspect variables.
Worked example
[2] A method meant to count the digits of n uses the loop while (n > 9) { c++; n = n / 10; } with c starting at 0. Find the error and correct it. (Analyse)
Try it first, then show the solutionSolution
- For n = 4075 the loop runs for 4075, 407, 40 and stops at 4, giving 3 instead of 4: a logical (off-by-one) error - 1 mark.
- Correct by using while (n > 0) (or by starting c at 1); test with 7 → 1 and 4075 → 4 - 1 mark.
Answer: The condition n > 9 skips the last digit; use while (n > 0) so every digit is counted (4075 → 4).
- Writing a Section B class: the standard pattern
Every Section B question follows the same shape. Marks are given for each method, for main( ) and for documentation.
1. Class header and data members exactly as named in the question (types as stated).
2. Constructor: initialise every data member to a legal initial value (0, "" or as specified). Constructors have no return type.
3. Input method: use Scanner to read values; follow any condition stated (for example lower case, positive integer).
4. Processing methods: implement the algorithm; respect the specified signature (parameters and return type); if the question says 'using recursive technique', the method must call itself with no loops.
5. Display or check method: call the processing methods as instructed (for example 'by invoking the function convert( )') and print results with clear messages.
6. main( ): create an object and call the methods in the right order.
7. Comments: describe each method's purpose and key variables (mnemonic names help).Example: class Emirp. An Emirp is a prime number whose reverse is a different prime (13 → 31).
Member Purpose int n, int rev the number and its reverse Emirp( ) constructor: n = 0, rev = 0 void accept( ) read n boolean isPrime(int x) true if x is prime void reverse( ) store the reverse of n in rev void check( ) use reverse( ) and isPrime( ) and print the result import java.util.Scanner; // An Emirp number is a prime whose reverse is a different prime (13 -> 31). public class Emirp { int n; // the number to test int rev; // its reverse Emirp() { n = 0; rev = 0; } void accept() { Scanner sc = new Scanner(System.in); System.out.println("Enter a positive integer:"); n = sc.nextInt(); } // returns true if x is prime boolean isPrime(int x) { if (x < 2) return false; for (int d = 2; d * d <= x; d++) if (x % d == 0) return false; return true; } // reverses n and stores the result in rev void reverse() { int t = n; rev = 0; while (t > 0) { rev = rev * 10 + t % 10; t = t / 10; } } void check() { reverse(); if (isPrime(n) && isPrime(rev) && rev != n) System.out.println(n + " is an Emirp number (reverse " + rev + " is also prime)"); else System.out.println(n + " is not an Emirp number"); } public static void main(String[] args) { Emirp ob = new Emirp(); ob.accept(); ob.check(); } }Sample input 13 gives:
Enter a positive integer: 13 is an Emirp number (reverse 31 is also prime)Other runs: 23 → not an Emirp (32 is not prime); 17 → Emirp (71); 11 → not an Emirp (reverse is the same number); 97 → Emirp (79).
Worked example
[2] In the Emirp program, why does check( ) test rev != n as well as both numbers being prime? (Analyse)
Try it first, then show the solutionSolution
- By definition the reverse must be a different prime - 1 mark.
- Palindromic primes such as 11 or 101 are prime and equal to their reverse, so without rev != n they would wrongly be accepted - 1 mark.
Answer: Because an Emirp's reverse must be a different prime; the extra test rejects palindromic primes such as 11.
Implementation of Algorithms to Solve Problems in real life
Each concept, met in an everyday situation. Read the situation, answer the question in your own words, then compare with the model answer. The one-line hook is what to remember.
Algorithm before code
Imagine planning a train journey: you decide the route and changes on paper before buying tickets, instead of boarding trains at random.
How is this like writing an algorithm before a program?
Try it first, then show the solutionSolution
- The route plan is the algorithm: clear steps from start to destination.
- Checking the plan (timings, connections) is the dry run; buying tickets and travelling is coding and running.
Answer: Designing and checking the algorithm first, like planning a route, avoids wasted effort and wrong turns when the program is written and run.
Memory hook: Plan the route, then take the train.
Boundary testing
Suppose a lift is rated for 8 people. Engineers test it with 1, 7, 8 and 9 people, not just 4.
Why test those numbers?
Try it first, then show the solutionSolution
- Errors usually occur at the edges: just inside, at and just beyond the limit.
- A program should likewise be tested at 0, 1, the largest value and just beyond it.
Answer: Boundary values reveal off-by-one and limit errors that typical values miss, so they must be part of every test plan.
Memory hook: Bugs live at the edges.
Logical error
Imagine a shop's billing program that compiles and runs perfectly but never adds the last item in the basket to the bill.
What kind of error is this, and how would you find it?
Try it first, then show the solutionSolution
- It runs without crashing but gives a wrong answer: a logical error (probably an off-by-one loop).
- Dry-run the loop with a small basket (one or two items) and compare with the expected total.
Answer: A logical error, found by testing small cases and tracing the loop, as with the digit-sum bug while (n > 9).
Memory hook: It runs is not the same as it is right.
Topics in this chapter
Implementation of Algorithms to Solve Problems: syntax and key facts
- Euclid's GCD
- gcd(a, b) = gcd(b, a % b); gcd(a, 0) = a
- LCM = a × b / GCD.
- Digit extraction
- last digit = n % 10; remove it: n = n / 10
- Loop while n > 0.
- Reverse a number
- rev = rev × 10 + n % 10; n = n / 10
- rev starts at 0.
- Prime test
- x ≥ 2 and no divisor d with 2 ≤ d and d × d ≤ x
- Checking up to the square root is enough.
- Error types
- Syntax (compile time) / run time (exception) / logical (wrong output)
- Logical errors need testing.
How the board asks Implementation of Algorithms to Solve Problems
The question patterns to expect, and the method that works for each.
| Question type | How it is asked | Method |
|---|---|---|
| Section B class design [10] | A class description (data members, constructor, methods) for a number, string or array problem; specify the class and write main( ). | Use the exact names and signatures; follow any instruction such as 'using recursive technique' or 'by invoking'; comment the code. |
| Dry run / output [2] + purpose [1] | Trace a given method for given input and state what it does. | Trace table, then a one-line general purpose. |
| Fill in the missing code [3] | A method with ?1?, ?2?, ?3? placeholders; supply the expressions. | Work out what each variable means, then test your answer by tracing one example. |
| Practical algorithm (Paper 2) | Write an algorithm, then the documented program, and run it on test data. | Numbered steps in structured English; test with normal and boundary data. |
Tricks to remember Implementation of Algorithms to Solve Problems
Short memory aids. Say each one aloud once, then use it on a question the same day.
C-A-P-D-M
Constructor, Accept, Process, Display, Main: the order of every Section B answer.
Use it when: Structure of a 10-mark program.
Three bugs
Compiler catches syntax; JVM catches run-time; only you catch logic.
Use it when: Error types.
Edge first
Test 0, 1, one-digit, largest and just-too-large values first.
Use it when: Correctness checks.
Implementation of Algorithms to Solve Problems: board-level solved questions
Ordered from board level to HOTS. Cover the solution, write your own, then compare step by step.
Example 1: Error type · 1 mark · MCQBoard level
A program compiles but stops with an ArrayIndexOutOfBoundsException. This is a:
(a) syntax error
(b) logical error that gives wrong output silently
(c) run-time error
(d) compile-time error
Try it first, then show the solutionSolution
- It compiled, so it is not a syntax or compile-time error.
- It stopped while running with an exception: a run-time error.
Answer: (c) run-time error.
Example 2: Algorithm property · 1 mark · Very short answerBoard level
Which property of an algorithm is violated by a loop whose control variable is never changed?
Try it first, then show the solutionSolution
- Such a loop never ends.
- An algorithm must finish after a finite number of steps.
Answer: Finiteness.
Example 3: Fill in the blanks: counting a digit · 3 marks · Short answerHarder board level
[3] The method below should return how many times the digit k occurs in a positive number n. Fill in ?1?, ?2? and ?3?.
int countDigit(int n, int k)
{
int c = ?1?;
while (n > 0)
{
if (?2?)
c++;
?3?;
}
return c;
}Try it first, then show the solutionSolution
- ?1?: c is a counter, so it starts at 0.
- ?2?: compare the last digit with k: n % 10 == k.
- ?3?: remove the last digit, n = n / 10. Check with n = 70770, k = 7: digits 0, 7, 7, 0, 7 → c = 3; with k = 0 the result is 2.
Answer: ?1? = 0; ?2? = n % 10 == k; ?3? = n = n / 10 (or n /= 10). countDigit(70770, 7) returns 3 (checked by running the code).
Example 4: Trace a loop · 2 marks · Short answerHarder board level
[2] Give the output of the following and state what the code computes in general.
int n = 1234, s = 0, k = 1;
while (n > 0)
{
s = s + (n % 10) * k;
k = -k;
n = n / 10;
}
System.out.println(s);Try it first, then show the solutionSolution
- Digits from the right: 4 × 1 = 4; 3 × (-1) → 1; 2 × 1 → 3; 1 × (-1) → 2. Output 2.
- It computes the alternating sum of digits from the right (the test used for divisibility by 11).
Answer: Output: 2. It finds the alternating digit sum (4 - 3 + 2 - 1), used to test divisibility by 11.
Example 5: Design a class: Emirp · 10 marks · Long answerHOTS / competency
[10] An Emirp number is a prime whose reverse is a different prime (for example 13, since 31 is prime). Design a class Emirp with data members n and rev; a constructor setting both to 0; void accept( ) to read n; boolean isPrime(int x); void reverse( ) to store the reverse of n in rev; and void check( ) that invokes reverse( ) and isPrime( ) and prints whether n is an Emirp. Write main( ). (Create)
Try it first, then show the solutionSolution
- Class header and data members int n, rev; constructor Emirp( ) sets n = 0, rev = 0.
- accept( ): Scanner reads n.
- isPrime(int x): false for x < 2; loop d from 2 while d × d ≤ x; any exact divisor → false; otherwise true.
- reverse( ): copy n to t; rev = rev × 10 + t % 10; t = t / 10 until t = 0.
- check( ): call reverse( ); if isPrime(n) and isPrime(rev) and rev != n print 'Emirp' else 'not Emirp'.
- main( ): create the object, call accept( ) then check( ). Full program and output are in the key concept 'Writing a Section B class'.
Answer: See the complete, compiled Emirp program above: input 13 prints '13 is an Emirp number (reverse 31 is also prime)'; 23 and 11 are reported as not Emirp numbers.
Example 6: Find and fix · 2 marks · Short answerHOTS / competency
[2] A student's prime test is: for (int d = 2; d <= x; d++) if (x % d == 0) return false; return true;. Explain why every number is reported as not prime and correct the loop. (Analyse)
Try it first, then show the solutionSolution
- When d reaches x, x % x == 0, so the method always returns false (and for x < 2 the logic is also wrong).
- Correct: if (x < 2) return false; for (int d = 2; d * d <= x; d++) if (x % d == 0) return false; return true;
Answer: The loop includes d = x, which always divides x. Stop before x (use d * d <= x) and reject x < 2 first.
Case-study practice (Section D style)
Read the situation, then answer every part. In the board paper this is a 7-mark question split into 2 + 2 + 2 + 1 marks.
A practical-exam problem (case-based)
In the practical examination a student must write a program to check Emirp numbers. She first writes the algorithm, then the code, then tests it with 13, 23, 11 and 1.
(i) · 2 marks
Write the algorithm for check( ) in numbered steps.
Answer
Answer: 1. Find rev, the reverse of n. 2. If n is prime, rev is prime and rev ≠ n, print 'Emirp'. 3. Otherwise print 'not Emirp'.
1 mark for reversal and tests, 1 for output.
(ii) · 2 marks
Give the expected output for 13 and 23.
Answer
Answer: 13: Emirp (31 prime). 23: not Emirp (32 is not prime).
1 mark each.
(iii) · 2 marks
Why are 11 and 1 good test values?
Answer
Answer: 11 tests the 'different prime' rule (palindromic prime); 1 tests the boundary where the number is not prime.
1 mark each.
(iv) · 1 mark
Name the kind of error if her program reports 11 as an Emirp.
Answer
Answer: A logical error (missing the rev != n condition).
1 mark.
Where the marks are
How a typical answer is split into step marks. Show every step: a right final answer alone rarely earns full marks.
[2] Find the error in a digit-counting loop and correct it. (2 marks)
| Step | Marks |
|---|---|
| Identifies the off-by-one condition with a trace. | 1 |
| Correct condition and test. | 1 |
[5] Algorithm and method isArmstrong with tests. (5 marks)
| Step | Marks |
|---|---|
| Algorithm steps. | 1 |
| Correct loop extracting digits. | 2 |
| Correct comparison and return. | 1 |
| Two suitable test values. | 1 |
[10] Class Emirp. (10 marks)
| Step | Marks |
|---|---|
| Data members and constructor. | 1 |
| accept( ) with Scanner. | 1 |
| isPrime(int). | 2 |
| reverse( ). | 2 |
| check( ) invoking the other methods, with rev != n. | 2 |
| main( ) creating the object and calling methods. | 1 |
| Documentation (comments, mnemonic names). | 1 |
Where students lose marks in Implementation of Algorithms to Solve Problems
The slips examiners see most often, and what to write instead.
Mistake: Using a loop where recursion is demanded
CISCE examiners' comments, 2024 and 2025: candidates 'Used a loop instead of recursion, or a mix of both' and had a 'Missing or wrong base case and badly structured recursive case; used loops instead of recursion'.
Do this: When the question says 'using recursive technique', the method must call itself, with a base case and no loop.
Usually costs: Most of that method's marks.
Mistake: Wrong or missing main( ) and object calls
CISCE examiners' comments: 2024 'object creation or method calls in main wrong'; 2025 'Object creation and method invocation in main( ) wrong, or main( ) omitted; no documentation'.
Do this: Always end with public static void main(String[] args): create the object with new, call the methods in order; add comments.
Usually costs: 1-2 marks.
Mistake: Not invoking a method when told to
CISCE examiners' comments, 2024: in display( ) candidates 'did not call convert( ), printed hexa before convert, or did not print both values'; 'used return in a void method'.
Do this: If the question says 'by invoking', call that method inside; match return types exactly.
Usually costs: 1-2 marks.
Mistake: Wrong starting value in fill-in-the-blank code
CISCE examiners' comments, 2024: on the smallest-digit method candidates 'Took initial min as 0 or -1' and were 'Unclear about the ? : operator'.
Do this: Ask what the variable must be before the loop so the first comparison works (minimum starts at 9 or the number itself), then test by tracing.
Usually costs: 1 mark per blank.
Practice questions on Implementation of Algorithms to Solve Problems
Write each answer on paper first. Open the hint only if you are stuck, and the answer only when you have finished.
Q1 · 1 mark · Very short answerBoard level
Name the error caused by a missing semicolon.
Hint
Compiler.
Answer
A syntax (compile-time) error.
Q2 · 1 mark · Very short answerBoard level
What is a dry run?
Hint
By hand.
Answer
Executing a program or algorithm by hand, recording the values of variables at each step, to check its output or correctness.
Q3 · 1 mark · Very short answerBoard level
Which exception occurs when an integer is divided by zero in Java?
Hint
Arithmetic.
Answer
ArithmeticException.
Q4 · 1 mark · Very short answerHarder board level
What is the output of the GCD loop for a = 17, b = 5?
Hint
17 % 5 = 2.
Answer
1 (17 % 5 = 2, 5 % 2 = 1, 2 % 1 = 0).
Q5 · 2 marks · Short answerHarder board level
[2] Write the loop to count how many digits of n are even.
Hint
n % 10 % 2.
Answer
int c = 0; while (n > 0) { if ((n % 10) % 2 == 0) c++; n = n / 10; } (for n = 4075 this gives 2: digits 0 and 4).
Q6 · 3 marks · Short answerHarder board level
[3] A method should return true if n is a perfect number (sum of proper divisors equals n). Fill in the blanks: int s = ?1?; for (int d = 1; d < n; d++) if (?2?) s += d; return ?3?;
Hint
Divisor test.
Answer
?1? = 0; ?2? = n % d == 0; ?3? = s == n. For n = 28: 1 + 2 + 4 + 7 + 14 = 28, so it returns true.
Q7 · 5 marks · Long answerHOTS / competency
[5] Write an algorithm and a Java method boolean isArmstrong(int n) that checks whether a 3-digit number equals the sum of the cubes of its digits. Give two test values.
Hint
153.
Answer
Algorithm: copy n to t, s = 0; while t > 0: d = t % 10, s = s + d × d × d, t = t / 10; return s == n.
boolean isArmstrong(int n) { int t = n, s = 0; while (t > 0) { int d = t % 10; s = s + d * d * d; t = t / 10; } return s == n; }Tests: 153 → true (1 + 125 + 27); 154 → false (1 + 125 + 64 = 190).
Q8 · 10 marks · Long answerHOTS / competency
[10] Design a class Twin with data members a and b (two integers); a constructor; void accept( ); boolean prime(int x); and void show( ) that prints whether a and b are twin primes (both prime and differing by 2), using prime( ). Write main( ).
Hint
Math.abs(a - b) == 2.
Answer
Constructor sets a = b = 0; accept( ) reads a and b with Scanner; prime(int x) returns false for x < 2 and checks divisors d with d × d ≤ x; show( ) prints 'Twin primes' if prime(a) && prime(b) && Math.abs(a - b) == 2, else 'Not twin primes'; main( ) creates an object and calls accept( ) and show( ). Tests: (11, 13) → twin primes; (13, 17) → not (difference 4); (7, 9) → not (9 is not prime).
Test your recall
Answer in your head or on paper first, then open the card. Pulling an answer out of memory makes it stick far better than re-reading.
1.Five properties of an algorithm?Show answer
Finiteness, definiteness, input, output, effectiveness.
2.Three kinds of error?Show answer
Syntax, run-time, logical.
3.Order of methods in a Section B answer?Show answer
Constructor, input, processing, display, main( ).
4.Why test boundary values?Show answer
Off-by-one and limit errors appear at the edges.
5.GCD of 84 and 36?Show answer
12.
Best order to study it
- Algorithm properties and how to design one.
- Dry runs and trace tables.
- Correctness and test data.
- Debugging and error types.
- Practise full Section B classes with main( ) and comments.
Quick revision checklist
The night before the exam: can you do each of these without looking?
- Algorithm: finite, definite, input, output, effective.
- Design: understand, examples, sub-tasks, steps, dry run, code.
- Trace table: one column per variable, one row per step.
- Test normal, boundary and special cases.
- Errors: syntax (compiler), run-time (exception), logical (wrong answer).
- Section B: exact names and signatures, recursion when asked, main( ), comments.
Implementation of Algorithms to Solve Problems: frequently asked questions
Do I need to write an algorithm in Section B of Paper 1?
No. The paper states that flowcharts and algorithms are not required there, but the program must show its logic through mnemonic names and comments. Algorithms are required in the practical paper.
Is BlueJ required?
The syllabus strongly recommends BlueJ for learning, but answers are written in standard Java; any Java 5.0 or later environment is acceptable.
How much documentation is enough?
A comment for the class and for each method, explaining its purpose, plus meaningful variable names. Examiners award marks for documentation.
Based on: CISCE ISC 2027 Computer Science (868) syllabus; CISCE ISC Computer Science (868) Paper 1 specimen question paper and answer key (latest specimen, 2025); CISCE Analysis of Pupil Performance, ISC Computer Science (868), 2025; CISCE Analysis of Pupil Performance, ISC Computer Science (868), 2024