Tuesday , 18 June 2019
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 : www.javaforschool.com
* @Program Type : BlueJ Program – Java
* @Question Year : ISC Theory 2013 Question 9

import java.io.*;
class Exchange
static BufferedReader br=new BufferedReader (new InputStreamReader (System.in));
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


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

Infix Postfix Prefix Conversion – Correct Method (ISC Computer Science)

In this video we discuss about the correct way of converting an Infix Expression to Postfix and Prefix.

Leave a Reply

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