Prashnikaप्रश्निका
Code
About
‹ Back to the paper

Question 2(iv)

3 marks

Computer ScienceISC 2025 Improvement Computer Science Paper 1Case basedImplementation of algorithms to solve problems

Fill in the blanks marked ?1?, ?2? ... so that the code works.

The following function getPart( ) is a part of some class which is used to extract h number of…

The following function getPart( ) is a part of some class which is used to extract h number of characters starting from index b of a string str. There are some places in the code marked by ?1?,?2?,?3? which must be replaced by an expression / statement so that the function works correctly.
String getPart(String str, int b, int h)
{
    int beg= ?1?;
    int end =b+h-1;
    String g="";
    while(beg<=?2? && beg>=0 && end<str.length() )
    {
        g+=str.charAt(beg);
        ?3?;
    }
    return g;
}
(a)[1]
What is the expression or statement at ?1?
(b)[1]
What is the expression or statement at ?2?
(c)[1]
What is the expression or statement at ?3?

Answer

Answer (a)

Blanks: b

?1? = $b$: the position of the first character to extract.

Answer (b)

Blanks: end

?2? = $end$: the loop runs while the index does not pass the last required character.

Answer (c)

Blanks: beg++

?3? = $beg++$: moves to the next character.