Prashnikaप्रश्निका
Code
About
Computer ScienceClass 12

Arrays, Strings - ISC Class 12 Computer Science Questions with Answers

48 past-paper questions on Arrays, Strings from ISC Class 12 Computer Science papers (2026-2017), newest first, in full. Questions 1-20 are on this page, 20 to a page. Tap "Show answer" under a question to see its answer. The syllabus covers Single and multi-dimensional arrays, Address calculations, Searching and sorting techniques, String class and operations and StringBuffer class.

48questions
10years
2026newest
20263 questions
2 marks · NumericalOpen: A matrix G[3...7, 2...5] is stored in the memory, with each element requiring 4…

Solve the following.

A matrix G[3...7, 2...5] is stored in the memory, with each element requiring 4 bytes of storage. If the address of G[5][4] is 6000, find the base address when the matrix is stored Column Major Wise.
Show answer

Answer

Row range: 3 to 7 -> Number of rows M = 7 - 3 + 1 = 5 Column range: 2 to 5 -> Number of columns N = 5 - 2 + 1 = 4 Element size W = 4 bytes Given Address(G[5][4]) = 6000 Column Major formula: Address(G[i][j]) = Base Address + W * [(j - Lc) * M + (i - Lr)] Here i = 5, j = 4, Lr = 3, Lc = 2 6000 = Base Address + 4 * [(4 - 2) * 5 + (5 - 3)] 6000 = Base Address + 4 * [2 * 5 + 2] 6000 = Base Address + 4 * [10 + 2] 6000 = Base Address + 4 * 12 6000 = Base Address + 48 Base Address = 6000 - 48 = 5952

Final answer: 5952

10 marks · ProgramOpen: Design a class PendulumS to perform an operation on a word containing alphabets…

Write the program described below.

Design a class PendulumS to perform an operation on a word containing alphabets in upper case only. Rearrange the word by putting the lowest ASCII value character at the centre and the second lowest ASCII value character to its right and the third to its left and so on. Example 1 : Input : COMPUTER Output : TPMCEORU Example 2 : Input : SCIENCE Output : SIECCEN The details of the members of the class are given below: Class name : PendulumS Data members/instance variables: wrd : to store the original word newwrd : to store the rearranged word Methods/Member functions: PendulumS(String k) : parameterised constructor to initialise wrd = k and newwrd = "" int minCharIndex(String str) : to find the index of the minimum ASCII value character in str and return it void arrange( ) : to rearrange the characters of wrd as per the given instructions and store it in newwrd by invoking minCharIndex( ) void display( ) : to display the original word and the rearranged word Specify the class PendulumS giving the details of the constructor( ), int minCharIndex(String), void arrange( ) and void display( ). Define the main( ) function to create an object and call the functions accordingly to enable the task.
Show answer

Answer

import java.util.Scanner;

class PendulumS
{
    String wrd;
    String newwrd;

    PendulumS(String k)
    {
        wrd = k;
        newwrd = "";
    }

    int minCharIndex(String str)
    {
        int minIdx = 0;
        char minCh = str.charAt(0);
        for (int i = 1; i < str.length(); i++)
        {
            if (str.charAt(i) < minCh)
            {
                minCh = str.charAt(i);
                minIdx = i;
            }
        }
        return minIdx;
    }

    void arrange()
    {
        String temp = wrd;
        int len = wrd.length();
        for (int i = 0; i < len; i++)
        {
            int idx = minCharIndex(temp);
            char ch = temp.charAt(idx);
            temp = temp.substring(0, idx) + temp.substring(idx + 1);

            if (i == 0)
            {
                newwrd = "" + ch;
            }
            else if (i % 2 == 1)
            {
                newwrd = newwrd + ch; // place to the right
            }
            else
            {
                newwrd = ch + newwrd; // place to the left
            }
        }
    }

    void display()
    {
        System.out.println("Original word: " + wrd);
        System.out.println("Rearranged word: " + newwrd);
    }

    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        System.out.print("Enter a word in uppercase: ");
        String input = sc.next();
        PendulumS obj = new PendulumS(input);
        obj.arrange();
        obj.display();
    }
}
Explanation: minCharIndex finds the index of the character with the minimum ASCII value in a string. arrange extracts characters in ascending ASCII order and alternately appends them to the right and prepends them to the left of the center character, forming the pendulum arrangement.
2 marks · NumericalOpen: An array Arr[3 … 8, -5 … 5] is stored Row Major Wise. The address of Arr[5][-2]…

Answer the following.

An array $Arr[3 \dots 8, -5 \dots 5]$ is stored Row Major Wise. The address of $Arr[5][-2]$ is $5120$. If each element occupies $4$ bytes in the memory, find the base address of the array.
Show answer

Answer

Row Major formula: Addr(Arr[i][j]) = Base + W × [ (i - LR) × NC + (j - LC) ] LR = 3, LC = -5, UC = 5, so NC = 5 - (-5) + 1 = 11; W = 4, i = 5, j = -2. Addr(Arr[5][-2]) = Base + 4 × [ (5 - 3) × 11 + (-2 - (-5)) ] 5120 = Base + 4 × [ 22 + 3 ] 5120 = Base + 4 × 25 5120 = Base + 100 Base = 5120 - 100 = 5020

Final answer: 5020

202517 questions
2 marks · NumericalOpen: A matrix M[-1...10, 4....13] is stored in the memory with each element…

Solve the following.

A matrix $M[-1...10, 4....13]$ is stored in the memory with each element requiring 2 bytes of storage. If the base address is 1200, find the address of $M[2][7]$ when the matrix is stored Row Major Wise.
Show answer

Answer

Row range $-1$ to $10$ $\to$ number of rows $M = 10-(-1)+1 = 12$ Column range $4$ to $13$ $\to$ number of columns $N = 13-4+1 = 10$ Each element $W = 2$ bytes; Base address $=1200$; target $M[2][7]$ Row Major formula: $Address(M[i][j]) = Base + W \times [(i - L_r) \times N + (j - L_c)]$ Here $i=2, j=7, L_r=-1, L_c=4$ $= 1200 + 2 \times [(2-(-1)) \times 10 + (7-4)]$ $= 1200 + 2 \times [30 + 3]$ $= 1200 + 66$

Final answer: 1266

1 mark · MCQOpen: The code snippet given below will result in: StringBuffer x = new…

Choose the correct option.

The code snippet given below will result in:
StringBuffer x = new StringBuffer("Hello");
StringBuffer y = new StringBuffer("HELLO");
System.out.println(x.equalsIgnoreCase(y));
  • (a)boolean value false
  • (b)boolean value true
  • (c)undeclared method equalsIgnoreCase(…)
  • (d)String literals mismatch.
Show answer

Answer

Correct option: c

Answer: (c) undeclared method equalsIgnoreCase( ). equalsIgnoreCase( ) is a String method, not a StringBuffer method. Since x and y are StringBuffer objects, calling x.equalsIgnoreCase(y) does not compile - it is an undefined method for that class.
1 mark · MCQOpen: For the following code snippet choose the correct output: int x = 234; String…

Choose the correct option.

For the following code snippet choose the correct output:
int x = 234; 
String str = String.valueOf(x) ; 
System.out.println(str.length( )); 
System.out.println( x + x ); 
System.out.println( str + str );
  • (a)2 234234 234234
  • (b)Error
  • (c)3 234234 468
  • (d)3 468 234234
Show answer

Answer

Correct option: d

Answer: (d) 3 468 234234. String.valueOf(234) gives "234", whose length( ) is 3. x + x adds the two int values numerically, giving 468. str + str concatenates the two Strings, giving "234234".
1 mark · MCQOpen: Assume int [ ] [ ] x = { {8,9} , {5,6,7},{1,2,3,4}}, what are x[0].length…

Choose the correct option.

Assume int [ ] [ ] x = { {8,9} , {5,6,7},{1,2,3,4}}, what are x[0].length, x[1].length, and x[2].length?
  • (a)2, 3 and 3
  • (b)2, 3 and 4
  • (c)3, 3 and 3
  • (d)2, 2 and 2
Show answer

Answer

Correct option: b

Answer: (b) 2, 3 and 4. x[0] = {8,9} has length 2, x[1] = {5,6,7} has length 3, and x[2] = {1,2,3,4} has length 4 - each row of this jagged array can have its own length.
1 mark · Assertion-reasonOpen: In Java, the String class is used to create and manipulate strings, and it is…

Study the Assertion and Reason and choose the correct option.

Assertion: In Java, the String class is used to create and manipulate strings, and it is immutable.

Reason: Immutability ensures that once a String object is created, its value cannot be changed.

Given below are two statements marked Assertion and Reason. Read the two statements carefully and choose the correct option.
  • (a)Both Assertion and Reason are true and Reason is the correct explanation for Assertion.
  • (b)Both Assertion and Reason are true but Reason is not the correct explanation for Assertion.
  • (c)Assertion is true and Reason is false.
  • (d)Assertion is false and Reason is true.
Show answer

Answer

Official answer key

Correct option: (a)

Answer: (a) Both Assertion and Reason are true and Reason is the correct explanation for Assertion. The Assertion is true: Java's String class is used to create and manipulate strings, and String objects are immutable. The Reason is true and directly explains the Assertion: immutability means that once a String object is created, its value/content can never be changed - any apparent modification actually creates a new String object.
2 marks · NumericalOpen: A matrix M[-6 … 10, 4 … 15] is stored in the memory with each element requiring…

Solve the following.

A matrix $M[-6 \dots 10, 4 \dots 15]$ is stored in the memory with each element requiring 4 bytes of storage. If the base address is 1025, find the address of $M[4][8]$ when the matrix is stored in column major wise.
Show answer

Answer

Official answer key
Column Major formula: Address(M[I][J]) = B + W x [(J - Lc) x M + (I - Lr)], where M = number of rows. Row range -6 to 10 => M = 10 - (-6) + 1 = 17 Column range 4 to 15 => N = 15 - 4 + 1 = 12 (not needed further, column major) Given: B = 1025, W = 4, I = 4, J = 8, Lr = -6, Lc = 4 Address(M[4][8]) = 1025 + 4 x [(8-4) x 17 + (4-(-6))] = 1025 + 4 x [4 x 17 + 10] = 1025 + 4 x [68 + 10] = 1025 + 4 x 78 = 1025 + 312 = 1337

Final answer: 1337

1 mark · OutputOpen: Find the output of the following snippet: void check1( ) { String x[ ] =…

What is the output of the following code?

Find the output of the following snippet:
void check1( ) 
{     
    String x[ ] = {"Kolkata", "Chennai", "Delhi"}; 
    String y[ ] = {"Kolkata", "Chennai", "Delhi"}; 
    System.out.println(x.equals(y)); 
}
Show answer

Answer

false Arrays do not override equals( ), so x.equals(y) uses the default Object.equals( ), which compares object references (memory addresses), not contents; since x and y are different array objects, it returns false even though their elements are equal.
1 mark · MCQOpen: What is the outcome of the following code snippet: public class Test { public…

Choose the correct option.

What is the outcome of the following code snippet:
public class Test  
{ 
    public static void main( )  
    { 
        char [ ][ ] matrix = {{'a','b','c'},{'p','q','r'},{'x','y','z'}}; 
        for( int i=0 ; i<3 ; i++) 
            System.out.print( matrix[i] [1] + "  " ); 
    }       
}
  • (a)a b c
  • (b)a p x
  • (c)p q r
  • (d)b q y
Show answer

Answer

Correct option: d

Answer: (d) b q y. matrix[i][1] picks the element at column index 1 of row i: for i=0 that is matrix[0][1]='b', for i=1 it is matrix[1][1]='q', and for i=2 it is matrix[2][1]='y', giving "b q y".
1 mark · MCQOpen: m and n are two StringBuffer objects. The method call, m.append(n) will:

Choose the correct option.

m and n are two StringBuffer objects. The method call, m.append(n) will:
  • (a)mutate object m.
  • (b)mutate object n.
  • (c)mutate both the objects m and n.
  • (d).append( ) is an accessor method so it cannot mutate any object.
Show answer

Answer

Correct option: a

Answer: (a) mutate object m. StringBuffer's append(x) method modifies the StringBuffer it is called on by appending x's content to it. So m.append(n) appends n's characters onto m, mutating m; n itself is left unchanged.
1 mark · Short answerOpen: String s1 = "Gujarat"; String s2 = new String("Gujarat"); String s3 = new…

Answer the following question.

String s1 = "Gujarat"; 
String s2 = new String("Gujarat"); 
String s3 = new String("Gujarat"); 
String s4 = "Gujarat";
How many String objects are created in the above snippet? Justify your answer.
Show answer

Answer

3 String objects are created. s1 = "Gujarat" is a literal, placed in the String constant pool. s4 = "Gujarat" is also a literal with the same content, so it reuses the same pooled object as s1 (no new object). s2 = new String("Gujarat") and s3 = new String("Gujarat") each use the new keyword, so each creates a separate new object in the heap, even though their content is the same. So in total: 1 (pool, shared by s1 and s4) + 1 (s2) + 1 (s3) = 3 objects.
10 marks · ProgramOpen: A class Mixarray contains an array of integer elements along with its capacity…

Write the program described below.

A class Mixarray contains an array of integer elements along with its capacity (More than or equal to 3). Using the following description, form a new array of integers which will contain only the first 3 elements of the two different arrays one after another. Example: Array1: { 78, 90, 100, 45, 67 } Array2: {10, 67, 200, 90 } Resultant Array: { 78, 90, 100, 10, 67, 200} The details of the members of the class are given below: Class name : Mixarray Data members/instance variables: arr[] : integer array cap : integer to store the capacity of the array Member functions/methods: Mixarray (int mm ) : to initialize the capacity of the array cap=mm void input( ) : to accept the elements of the array Mixarray mix(Mixarray P, Mixarray Q) : returns the resultant array having the first 3 elements of the array of objects P and Q void display( ) : to display the array with an appropriate message. Specify the class Mixarraygiving details of the constructor(int), void input( ), Mixarray mix(Mixarray,Mixarray) and void display( ). Define a main( ) function to create objects and call all the functions accordingly to enable the task.
Show answer

Answer

Official answer key
import java.util.Scanner;

class Mixarray
{
    int arr[];
    int cap;

    Mixarray(int mm)
    {
        cap = mm;
        arr = new int[cap];
    }

    void input()
    {
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter " + cap + " elements:");
        for (int i = 0; i < cap; i++)
            arr[i] = sc.nextInt();
    }

    Mixarray mix(Mixarray P, Mixarray Q)
    {
        Mixarray res = new Mixarray(6);
        int k = 0;
        for (int i = 0; i < 3; i++)
            res.arr[k++] = P.arr[i];
        for (int i = 0; i < 3; i++)
            res.arr[k++] = Q.arr[i];
        return res;
    }

    void display()
    {
        System.out.println("Resultant array:");
        for (int i = 0; i < cap; i++)
            System.out.print(arr[i] + " ");
        System.out.println();
    }

    public static void main(String args[])
    {
        Scanner sc = new Scanner(System.in);
        System.out.print("Enter capacity of first array (>=3): ");
        int c1 = sc.nextInt();
        Mixarray P = new Mixarray(c1);
        P.input();

        System.out.print("Enter capacity of second array (>=3): ");
        int c2 = sc.nextInt();
        Mixarray Q = new Mixarray(c2);
        Q.input();

        Mixarray R = new Mixarray(6);
        Mixarray res = R.mix(P, Q);
        res.display();
    }
}
Explanation: mix(P,Q) creates a new Mixarray object of capacity 6, copies the first three elements of P into it followed by the first three elements of Q, and returns it. Tested with Array1={78,90,100,45,67} and Array2={10,67,200,90}: the program correctly outputs the resultant array 78 90 100 10 67 200 (verified by running the code), matching the example in the question.
10 marks · ProgramOpen: [Programme based on Strings] Two words are called anagram of each other if both…

Write the program described below.

[Programme based on Strings] Two words are called anagram of each other if both the words contain the same letters but they are arranged in different order. Following are the three pairs of the words which are anagrams of each other. cat, act heart, earth silent, listen Design the class Anagram to input two words in lower case and check if they are anagram of each other. The member functions and data members of the class are given below: Class Name : Anagram Data members/instance variables: s1, s2 : stores the two words in lower case l1, l2 : number of character in s1 and s2 respectively Member functions : Anagram(String s1, String s2) : parameterised constructor to assign the accepted values of s1 and s2 to data member void sort(char c[]) : to sort the characters in array c[ ] in ascending order using any sorting technique boolean areAnagram(char[] str1, char[] str2) : to check if str1 and str2 are anagrams of each other and to return true or false accordingly void check() : to convert the two strings into two character arrays and to display the appropriate message as shown in the sample output by calling the method areAnagram(char[] str1, char[] str2) Specify the class Anagram giving details of the parameterised constructor, void sort(char c[ ]), boolean areAnagram(char[] str1, char[] str2) and void check( ). Create one object in the main( ) method and call all the methods appropriately.

Sample input/output

Sample input
Enter first word->earth
Enter second word->heart

Output
earth and heart are anagram of each other
Show answer

Answer

import java.util.Scanner;

class Anagram
{
    String s1, s2;   // the two words in lower case
    int l1, l2;      // number of characters in s1 and s2

    // parameterised constructor
    Anagram(String s1, String s2)
    {
        this.s1 = s1;
        this.s2 = s2;
        l1 = s1.length();
        l2 = s2.length();
    }

    // sorts the characters of c[] in ascending order using bubble sort
    void sort(char c[])
    {
        int n = c.length;
        for (int i = 0; i < n - 1; i++)
            for (int j = 0; j < n - 1 - i; j++)
                if (c[j] > c[j + 1])
                {
                    char t = c[j];
                    c[j] = c[j + 1];
                    c[j + 1] = t;
                }
    }

    // checks if str1 and str2 are anagrams by sorting both and comparing
    boolean areAnagram(char[] str1, char[] str2)
    {
        if (str1.length != str2.length)
            return false;
        sort(str1);
        sort(str2);
        for (int i = 0; i < str1.length; i++)
            if (str1[i] != str2[i])
                return false;
        return true;
    }

    // converts s1 and s2 to character arrays and displays the result
    void check()
    {
        char c1[] = s1.toCharArray();
        char c2[] = s2.toCharArray();
        if (areAnagram(c1, c2))
            System.out.println(s1 + " and " + s2 + " are anagram of each other");
        else
            System.out.println(s1 + " and " + s2 + " are not anagram of each other");
    }

    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        System.out.print("Enter first word->");
        String s1 = sc.next();
        System.out.print("Enter second word->");
        String s2 = sc.next();
        Anagram ob = new Anagram(s1, s2);
        ob.check();
    }
}
Explanation: sort() rearranges a character array into ascending order with bubble sort; areAnagram() sorts copies of both words and returns true only if every position then matches (same length and same multiset of letters). check() converts the two stored words to char arrays and prints the appropriate message. Tested (run for real): "earth"/"heart" printed "earth and heart are anagram of each other" (matching the sample), "silent"/"listen" also correctly reported as anagrams, and "hello"/"world" was correctly reported as not anagrams.
1 mark · MCQOpen: String Description StringA Password entered by the user StringB Password stored…

Choose the correct option.

StringDescription
StringAPassword entered by the user
StringBPassword stored by the system
Passwords are stored as two Strings-one is the user entered password saved in StringA, the other is a password stored by the system in StringB. If StringA must be checked with StringB, for validity, which one of the following String functions are needed to be used?
  • (a)charAt( )
  • (b)equals( )
  • (c)equalsIgnoreCase( )
  • (d)startsWith( )
Show answer

Answer

Correct option: b

Answer: (b) equals( ). A password check needs an exact, case-sensitive comparison, which String's equals( ) method gives. equalsIgnoreCase( ) would wrongly accept passwords differing only in case, and charAt( )/startsWith( ) do not compare the whole string.
2 marks · NumericalOpen: A matrix P[-10…10, 1…10] is stored in the memory with each element requiring 2…

Solve the following.

A matrix $P[-10\dots10, 1\dots10]$ is stored in the memory with each element requiring 2 bytes of storage. If the base address is 2000, find the address of $P[5][6]$ when the matrix is stored Row Major wise.
Show answer

Answer

Row Major formula: Addr(P[i][j]) = Base + W × [ (i - LR) × NC + (j - LC) ] Here LR (lower row bound) = -10, LC (lower column bound) = 1, UC (upper column bound) = 10, so NC (number of columns) = UC - LC + 1 = 10; W = 2, Base = 2000, i = 5, j = 6. Addr(P[5][6]) = 2000 + 2 × [ (5-(-10)) × 10 + (6-1) ] = 2000 + 2 × [ 15 × 10 + 5 ] = 2000 + 2 × 155 = 2000 + 310

Final answer: 2310

About Arrays, Strings

Arrays, Strings is a unit of the ISC Class 12 Computer Science syllabus.

The syllabus lists these topics: Single and multi-dimensional arrays, Address calculations, Searching and sorting techniques, String class and operations and StringBuffer class.

Prashnika has 48 past-paper questions on Arrays, Strings, from papers of 2017-2026, asked in 10 different years. By kind: Numerical (13), Program (13), MCQ (12) and Short answer (4). They carry between 1 and 15 marks, and most are worth 2 marks.

To practise, use the 2D array visualiser and the paper generator, which can build a practice paper from this chapter.

Common questions

What topics are in Arrays, Strings in ISC Class 12 Computer Science?

The syllabus lists Single and multi-dimensional arrays, Address calculations, Searching and sorting techniques, String class and operations and StringBuffer class.

How many questions on Arrays, Strings are in ISC Class 12 Computer Science past papers?

Prashnika has 48 questions on Arrays, Strings, from papers of 2017-2026 (board, specimen, improvement and practice papers together).

What kinds of questions are asked on Arrays, Strings?

By kind: Numerical (13), Program (13), MCQ (12) and Short answer (4).

Questions on other pages on Arrays, Strings