Monday , 19 November 2018
Home » Class 12 » [Question 9] ISC 2013 (Theory) Paper Solved

[Question 9] ISC 2013 (Theory) Paper Solved


Design a class Exchange to accept a sentence and interchange the first alphabet with the last alphabet for each word in the sentence, with single letter word remaining unchanged. The words in the input sentence are separated by a single blank space and terminated by a full stop.

Example: Input: It is a warm day.
Output: tI si a marw yad

Some of the data members and member functions are given below:

Class name : Exchange

Data members/instance variables:
sent : stores the sentence
rev : to store the new sentence
size : stores the length of the sentence

Member functions:
Exchange() : default constructor
void readsentence() : to accept the sentence
void exfirstlast() : extract each word and interchange the first and the last alphabet of the word and form a new sentence ‘rev’ using the changed words
void display() : display the original sentence along with the new changed sentence.

Specify the class Exchange giving details of the constructor(), void readsentence(), void exfirstlast() and void display(). Define the main() function to create an object and call the function accordingly to enable the task.

Programming Code:

* The class Exchange inputs a sentence and interchanges the first alphabet 
* with the last alphabet for each word in the sentence
* @author :
* @Program Type : BlueJ Program - Java
* @Question Year : ISC Theory 2013 Question 9

class Exchange
static BufferedReader br=new BufferedReader (new InputStreamReader (;
String sent, rev;
int size;

Exchange() //default constructor

void readsentence()throws IOException
    System.out.print("Enter a sentence : ");
    if(sent.charAt(size-1)!='.') // checking whether the sentence ends in a fullstop or not.
    { //If not, then we are adding a fullstop and increasing the length by 1

void exfirstlast()
    String s1=""; //temporary String variable for holding each word as it is extracted
    char ch;
    for(int i=0;i<size;i++)
      if(ch!=' ' && ch!='.')
      else //else will execute when 's1' will have a complete word in it
       int l=s1.length(); //finding length of the extracted word
/*The Main Exchange Process Starts Here*/
       for(int j=0;j<l;j++)
         if(j==0) //exchanging the first alphabet with the last
         else if(j==(l-1)) //exchanging the last alphabet with the first
         rev=rev+ch; //adding the characters to the new String
       rev=rev+" "; //after completion of a word, a space is added to the new String
       s1=""; //the temporary String variable is emptied

void display()
    System.out.println("The Original Sentence is : "+sent);
    System.out.println("The Changed Sentence is : "+rev);

public static void main(String args[])throws IOException
    Exchange ob=new Exchange();


Enter a sentence : Today was a warm day.
The Original Sentence is : Today was a warm day.
The Changed Sentence is : yodaT saw a marw yad

Enter a sentence : This is a cat
The Original Sentence is : This is a cat.
The Changed Sentence is : shiT si a tac

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.

Leave a Reply

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