Wednesday , 18 July 2018
Home » Class 12 » ISC 2014 [Question 10] Theory Paper Solved – Fibonacci String

ISC 2014 [Question 10] Theory Paper Solved – Fibonacci String


A sequence of Fibonacci Strings is generated as follows:

S0 = “a”, S1 = “b”, Sn = S(n-1) + S(n-2) where ‘+’ denotes concatenation. Thus the sequence is:

a, b, ba, bab, babba, babbabab, ………. n terms.

Design a class FiboString to generate Fibonacci strings. Some of the members of the class are given below:

Class name         :               FiboString

Data members/instance variables:

x                              :               to store the first string
y                              :               to store the second string
z                              :               to store the concatenation of the previous two strings
n                             :               to store the number of terms

Member functions/methods:

FiboString()        :               constructor to assign x=”a”, y=”b”, z=”ba”
void accept()      :               to accept the number of terms ‘n’
void generate()   :               to generate and print the fibonacci strings. The sum of (‘+’ i.e. concatenation) first two strings is the third string. Eg. “a” is first string, “b” is second string then the third string will be “ba” and fourth will be “bab” and so on.

Specify the class FiboString, giving details of the constructor(), void accept() and void generate(). Define the main() function to create an object and call the functions accordingly to enable the task.

Programming Code:

* The class FiboString prints the sequence of fibonacci strings
* @author :
* @Program Type : BlueJ Program - Java
* @Question Year : ISC 2014 Question 10 (Theory)

class FiboString
    String x,y,z;
    int n; 
    FiboString() // Constructor
        x = "a";
        y = "b";
        z = "ba"; // mentioned in the question otherwise not required. z = "" is sufficient
    void accept()throws IOException
        BufferedReader br = new BufferedReader(new InputStreamReader(;
        System.out.print("\nEnter the number of terms : ");
        n = Integer.parseInt(br.readLine());
    void generate()
        System.out.print("nThe Fibonacci String Series is : ");
        if(n <= 1) // If no of terms is less than or equal to 1
        else // If no of terms is more than or equal to 2
            System.out.print(x+", "+y);
            for(int i=3; i<=n; i++)
                z = y+x;
                System.out.print(", "+z);
                x = y;
                y = z;
    public static void main(String args[]) throws IOException
        FiboString ob = new FiboString();


1) Enter the number of terms : 2
The Fibonacci String Series is : a, b

2) Enter the number of terms : 5
The Fibonacci String Series is : a, b, ba, bab, babba

Check Also

ISC 2017 Computer Science Solution + Examiner’s Comments – From the Council

Solution of ISC 2017 Computer science Paper as provided by the Council for the Indian School Certificate Examinations.


  1. Helpfull website

  2. Nice program…very simple code..easy to understand….and remember

Leave a Reply

Your email address will not be published. Required fields are marked *