Thursday , 25 May 2017
Home » Class 12 » ISC 2013 [Question 3] Practical Paper Solved

ISC 2013 [Question 3] Practical Paper Solved

Question:

Palindrome is a word that may be read the same way in either direction.

Accept a sentence in UPPER CASE which is terminated by either ” . “, ” ? ” or ” ! “.

Each word of the sentence is separated by a single blank space.

Perform the following tasks:

(a) Display the count of palindromic words in the sentence.
(b) Display the Palindromic words in the sentence.

Example of palindromic words: MADAM, ARORA, NOON

Test your program with the sample data and some random data:

Example 1

INPUT : MOM AND DAD ARE COMING AT NOON.

OUTPUT : MOM DAD NOON
NUMBER OF PALINDROMIC WORDS : 3

Example 2

INPUT : NITIN ARORA USES LIRIL SOAP.

OUTPUT : NITIN ARORA LIRIL
NUMBER OF PALINDROMIC WORDS : 3

Example 3

INPUT : HOW ARE YOU?

OUTPUT : NO PALINDROMIC WORDS

Programming Code:

/**
* The class Palin_ISC2013 inputs a sentence and prints all the Palindromic words in it
* along with it's frequency
* @author : www.javaforschool.com
* @Program Type : BlueJ Program - Java
* @Question Year : ISC Practical 2013 Question 3
*/

import java.io.*;
import java.util.*;
class Palin_ISC2013
{
static BufferedReader br=new BufferedReader (new InputStreamReader (System.in));

boolean isPalin(String s)
{
int l=s.length();
String rev="";
for(int i=l-1; i>=0; i--)
{
rev=rev+s.charAt(i);
}
if(rev.equals(s))
return true;
else
return
false;
}

public static void main(String args[])throws IOException
    {
        Palin_ISC2013 ob=new Palin_ISC2013();
        System.out.print("Enter any sentence : ");
        String s=br.readLine();
        s=s.toUpperCase();

        StringTokenizer str = new StringTokenizer(s,".?! ");
        int w=str.countTokens(); 

        String word[]=new String[w];
        for(int i=0;i<w;i++)
        {
            word[i]=str.nextToken();
        }

        int count=0;
        System.out.print("OUTPUT : ");
        for(int i=0; i<w; i++)
        {
            if(ob.isPalin(word[i])==true)
            {
                count++;
                System.out.print(word[i]+" ");
            }
        }

        if(count==0)
        System.out.println("No Palindrome Words");
        else
        System.out.println("nNumber of Palindromic Words : "+count);
    }
} 

Output:

1. Enter any sentence : MOM AND DAD ARE COMING AT NOON.
OUTPUT : MOM DAD NOON
Number of Palindromic Words : 3

2. Enter any sentence : HOW ARE YOU?
OUTPUT : No Palindrome Words

Check Also

[Question 2] ISC 2017 Computer Practical Paper Solved – Quiz Result

Solution of Program 2 of ISC 2017 Computer Science Paper 2 (Practical) Exam. Java program to input the answers of each participant row-wise and calculate their marks

Leave a Reply

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