PRASHNIKAप्रश्निका
Back to the paper

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

Computer Science20253 marksFill in
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.0]
What is the expression or statement at ?1?
(b)[1.0]
What is the expression or statement at ?2?
(c)[1.0]
What is the expression or statement at ?3?

Answer

Answer (a)

AI
?1? is `b` (the extraction must start from index b, the given lower bound of the substring).

Answer (b)

AI
?2? is `end` (beg must not exceed end, the last index up to which characters are to be extracted, for the loop to keep running).

Answer (c)

AI
?3? is `beg++` (or beg = beg + 1;), to move to the next character position in each iteration of the loop.
Implementation of algorithms to solve problems

From ISC 2025 Improvement Computer Science Paper 1, question 2(iv).