Archive

Author Archive

Last Minute Suggestion -2013

March 10, 2013 31 comments

For Section A, study theory well and practice operators and java statements well.

For Section B, you must know:

1. questions on slab rate like the taximeter one f 2012 paper

2. String manipulations- for  this study string and character functions well and must know how to extract a word from the given sentence

3. Single Dimensional Arrays – taking inputs in an array, printing array, summing array elements,  searching, sorting, working on two corresponding arrays,etc

4. function overloading with menu-driven programs

5. constructor overloading with object creation for both parameterized and non-parameterized constructor

6. pattern programs

7 series programs

Maintain cool, read the questions carefully understanding them well, make the correct choice, time your answers, think before writing and revise.

All the best for your exam.

How to write variable description

March 10, 2013 19 comments

Variable description has to be given with each program in Section B. Let us take an example. Make two columns  and give the headings ‘variable name’ and ‘used for’ as I have described below:

class DoubleLetter  {

void count(String s1) {

s=s1.toUpperCase();

int l=s.length();

int c=0;

for( int p=0; p<l-1;  p++)

{

if(s.charAt(p) == s.charAt(p+1))

c++;

}//for ends

System.out.println( c  );

}//method ends

}//class ends

variable description

s1 – to store inputted string

s –  to store s1 converted to uppercase

l – t store length of s1

c – cunter to count the number of double letter words that exist in the string s

p – loop control variable to generate string subscripts

Understanding Patterns

February 22, 2013 5 comments

Since Pattern programs are important for ICSE Computer Applications Examination, I have tried to explain them in this post.

To understand patterns first go to the link  and understand loops. 

A pattern is also a combination of rows and columns. For each Row there are a number of columns like an Excel Sheet. Let’s take an example to illustrate it better:

@@@@
@@@@
@@@@
@@@@

1. In the above pattern  there are four rows and four columns in each row.

2. The rows are controlled by outer loop, hence it should runs four times.

3. There are 4 ‘@’ on each row which represent columns of the row.  It means for each row, there should be 4 columns. Since  columns are controlled by the inner loop, on each iteration of the outer loop, inner loop must  also run  4 times. 
4. The program code would be:

for( int i=0; i< 4; i++)

{

for( int j=0; j< 4; j++)

{

System.out.print(“@”);

}

System.out.println();

}

The statement given below is the inner loop:

for( int j=0; j< 4; j++)

{

System.out.print(“@”);

}

When the outer loop ‘for( int i=0; i< 4; i++)’ runs for the first time, the inner loop catches the control and executes  four times printing the symbols in the fixed row ( determined by ‘i’) but in different columns. After the inner loop has executed four times, the control goes out of its body and cursor comes to the next line to start printing on the next Row. A full course iteration of the inner loop means one iteration of the outer loop. As the outer loop starts its second iteration again, the inner loop also starts again and executes for another full course, means four times as defined. So the inner loop runs for a total of 16 times and the symbol is also printed for a total of 16 times. There are four rows in the pattern and the outer loop has executed for four times only. 

The complete code for this program is:

 class Pattern

{

public void  showPattern()

{

for( int i=0; i< 4; i++)

{

for( int j=0; j< 4; j++)

{

System.out.print(“@”);

}

System.out.println();

}

}

}

IMPORTANT: In the inner loop  System.out.print() statement is used since all the characters have to printed on the same Row. And when the inner loop ends, one blank println() is given to bring the cursor to the next Row to begin printing characters on this new Row.

Lets take another example:

A
AA
AAA
AAAA

As  told above  that first  we have to count the number of rows. Here the row numbers are 4, so the outer loop will execute four times. The number of columns in all the rows are not same but there is a sequence in which they are increased. In each iteration the number of columns increases by 1. The outer loop will execute for 4 times  but the inner loop will execute variable number of times.

So we take a variable for the inner loop that increases by 1 after each full course iteration of the inner loop. And since the outer loop control variable increases by 1 after each of it’s iteration, we can use the outer loop control variable in the conditional statement of the inner loop.

The full code would be:

class Pattern
{
public void show()
{
for(int i=0;i< 4; i++)
{
for( int j=0; j< = i ; j++)
{
System.out.print(“A”);
}
System.out.println();
}
}
}

Let us take one more example:

1 1
 12 3
123 6
1234 10
12345 15
class pattern
{
int i,j,k,m,x;
void show()
{
x=0;
for(i=1;i< =5;i++)
{
for(j=1;j< =i;j++)
{
System.out.print(j);
}
x=x+i;
System.out.println(” “+x);
 }
 }
}
 In the above program the  inner loop iteration is not fixed. As the outer loop executes, the inner loop execution increases. At the end of execution of the inner loop each time it prints the sum of the digits of that row with a space. As the inner execution increases after each iteration, outer loop control variable is set in the conditional statement of the inner loop. As the control leaves the inner loop, it prints the sum of the digits.
Here’s another example:
123454321
 1234 4321
123   321
12     21
1       1
class pattern
{
int i,j,k,m,x;
void show()
{
for(i=0;i< 5;i++)
{
x=1;
for(j=i;j< 5;j++)
System.out.print(x++);
for(k=0;k<  i; k++)
System.out.print(” “);
x=x-1;
for(m=i;m< 5;m++)
System.out.print(x–);
System.out.println();
}
}
}
This above pattern is displayed using three inner loops inside the outer loop. Outer loop as usual generates the rows. First inner loop displays one digit more than that of the third inner loop. The middle inner loop displays the blank spaces of the pattern. Each time the first inner loop starts with ‘1’ and go on incrementing. When the control leaves the first inner loop the middle inner loop catches the control. Again the third inner loop starts from a value less than 2 of the last value of the loop control variable of first inner loop.

For further practice on patterns click on this link

 


 

ICSE Computer Applications-2013 (Marking Scheme Guidelines)

February 15, 2013 53 comments

Marking scheme is confidential but here’s an idea about how to answer the two sections.

 
Section A - Each question carries the marks specified in front of it. Read the question carefully and answer only how much is asked. For example, if one difference is asked, then write only one. But if you are not sure of the answer then write more. The one that is correct would be marked. You can also keep the following points in mind while answering this section:-
(a) Write to the point precise answers . Use keywords while answering definitions, differences, etc. For example, Constructor is a member function with the same name as class and no return type. (Here, no return type  and name same as class  are important keywords)
(b) Write differences, if asked,  making two  columns. Write example of each, if you know
(c) Do not leave any answer. Even if you don’t know, write something as marking is not negative.
(d) While attempting “write the output” type of questions, show the “Dry Run” working.
(e) While attempting “solve” type of questions based on operators, show all the steps. Read the data types used  in the arithmetic expression carefully for showing the final answer.
(f) Learn the definitions and syntax of various string, mathematical and character functions very well.  Should  know the three loops well and their inter conversions.  Should know the definitions and syntax of all “if”  structures and “switch-case-default” well and their inter-conversions. Study ternary operator.  Learn the definitions and example of OOP principles .  Theory is important for this section.
Section B: The marking in this section is step-wise so need not worry. Plan the program before you start writing as can’t afford to waste time in cancelling and re-writing.
(a) Write  variable -description for each program (after or before ) the program. Don’t forget as it carries marks.
(b) Read the question carefully and do not forget any step. So write the program step by step keeping all points in mind.
(c) Write one -two comments for each program if time is left.
(d) Try to indent the program as it makes it neat.
(e) Study if structures, loops, arrays and strings well for this section. Also revise sorting and searching methods. Must know mathematical and string functions as they might be needed for such questions.
Careful and correct answering may lead to a full score of 100.
Best wishes for your exams.

ISC Computer Science Practical Paper-2013

February 11, 2013 16 comments

COMPUTER SCIENCE

Paper – 2

(PRACTICAL)

(Reading Time: 15 minutes)

 (Planning Session AND Examination Session: Three Hours)

————————————————————————————————————

The total time to be spent on the Planning and the Examination Session is Three hours.

After completing the Planning Session, the candidate may begin with the Examination Session.

A maximum of 90 minutes is permitted to begin the Examination Session.

(Maximum Marks: 80)

————————————————————————————————————

As it is a practical examination the candidate is expected to do the following:

  1. Write an algorithm for the selected problem. Algorithm should be expressed clearly using ay standard scheme such as pseudo code or in steps which are simple enough to be obviously computable.  [10]
  2. Write a program in JAVA language. The program should follow the algorithm and should be logically and syntactically correct. [20]
  3. Document the program using mnemonic names / comments, identifying and clearly describing the choice of data types and meaning of variables. [20]
  4. Code / Type the program on the computer and get a printout (hard copy). Typically this should be a program that compiles and runs correctly. [10]
  5. Test run the program on the computer using the given sample data and get a printout of the output in the format specified in the problem. [20]
  6. Viva-Voce on the Selected Problem.   [20]

Solve any one of the following Problems:

 Question 1.

An ISBN (International Standard Book Number) is a ten digit code which uniquely identifies a book.

The first nine digits represent the group, publisher and title of the book and the last digit is used to check whether ISBN is correct or not.

Each of the first nine digits of the code can take a value between 0 to 9. Sometimes it is necessary to make the last digit equal to ten. This is done by writing the last digit of the code as X.

To verify an ISBN, calculate 10 times the first digit, plus 9 times the second digit, plus 8 times the third digit and so on until we add 1 time the last digit. If the final number leaves no remainder while divided by 11, the code is a valid ISBN

For example:

0201103311=10*0+9*2+8*0+7*1+6*1+5*0+4*3+3*3+2*1+1*1=55

This is a valid ISBN

007462542X=10*0+9*0+8*7+7*4+6*6+5*2+4*5+3*4+2*2+1*10=176

This is a valid ISBN

Similarly 0112112425 is not a valid ISBN.

 Test Data:

Input code: 0201530821

Output: Sum=99

Leaves no remainder – valid ISBN

Input code: 356680324

Output: Sum=invalid input

Input code: 0231428031

Output: Sum=122

Leaves remainder – invalid ISBN

Question 2:

Write a program to declare a square matrix A[][] of order (MXN) where ‘M’ is the number of rows and the number of columns. ‘M’ should be greater than 2 and less than 20. Allow user to enter integers into this matrix. Display appropriate error message for an invalid input. Perform the following tasks.

1.    Display the input matrix

2.    Create a mirror image of the inputted matrix.

3.    Display the mirror image matrix

Test Data:

Input: M=3

4  16  12

8   2  14

6   1   3

Output:

Original matrix

4  16  12

8   2  14

6   1   3

Mirror image matrix:

12  16  4

14  2    8

3   1    6

Input: M=22

Output: Size out of range

Question 3:

A palindrome is a word that may be read the same in either direction.

Accept a sentence in upper case which is terminated by either ‘.’  ,  ’,’  ,  ‘? ’ ,  ‘!’. Each word in the sentence is separated by a blank space.

Perform the following tasks:

Test Data:

Input: MOM AND DAD ARE COMING AT NOON.

Output: MOM DAD NOON

Number of palindromic words: 3

Input: HOW ARE YOU?

Output: No palindromic words

 

For solutions you can see the comments below as students have posted the codes there.

 

ISC Specimen Paper ( Computer Science Theory) – 2013

February 9, 2013 Leave a comment
COMPUTER  SCIENCE
PAPER 1 
(THEORY) 
Three hours
(Candidates are allowed additional 15 minutes for only reading the paper.
They must NOT start writing during this time.)
—————————————————————————————————————-
Answer all questions in Part I (compulsory) and seven questions from Part-II,  choosing
three questions  from  Section-A,  two  from Section-B and two from Section-C . 
All working, including rough work, should be done on the same sheet as the
rest of the answer.
The intended marks for questions or parts of questions are given in brackets [  ].
—————————————————————————————————————-
PART I
Answer all questions.
While answering questions in this Part, indicate briefly your working and reasoning,
wherever required.
Question 1      
(a)  State the two distributive laws of Boolean Algebra.  Prove any one of them with the help of Truth Table.  [2]
(b) Draw the truth table to verify the expression :
p ⇒ q is equivalent to ∼ q ⇒ ∼ p   (∼ q =  q = q’)       [2]
(c) Find the complement of the following:
         [(xy)′ • x] [ (xy)′ • y]             [2]
(d) Simplify the following Boolean Expression using laws of Boolean Algebra.  At each step, clearly state the law used for simplification.
z . ( z + x ) x ( y +  y )           [2]
(e)  Given     F ( x, y, z ) = xz + xy + yz
Write the function in canonical sum of products form.    [2]
Question 2 
(a) What do LIFO and FIFO stand for?  [2]
(b) For an array of real numbers x [ − 6… 8 , -12… 20 ] , find the address of
  x [5] [4 ],  if x  [1] [1]  is stored in location 100 in the column major order.
Assume that each element requires 4 bytes.  [2]
(c)  State the difference between an abstract class and an interface  [2]
(d) Convert the following infix expression to its postfix form:
     b * [ (a / d )  -   ( c * ( e  -  f ) ) ]      [2]
(e) Define a binary tree.  [2]
Question 3
(a) The following function is a part of some class.  It returns the value 1 when the number is an Armstrong number, otherwise it returns 0.
/* An Armstrong number  is a number which is equal to the sum of the cube of
its individual digits */
           int arms ( int n )
           {
                int digit = 0, sum = 0 ;
                int rem = n;
                while ( ? 1 ? )
                 {
                     digit = ? 2 ?;
                     sum = sum + ? 3 ? ;
                     rem = ? 4 ? ;
                 }
                if (? 5 ? )
                   return 1 ;
                else
                   return 0 ;
           }
(i) What is the expression/value at ? 1 ?  [1]
(ii) What is the expression/value at ? 2 ?  [1]
(iii) What is the expression/value at ? 3 ?  [1]
(iv) What is the expression/value at ? 4 ?  [1]
(v) What is the expression/value at ? 5 ?  [1]
(b)  Give output of the following function where x and y are arguments greater than 0. Show the dry run/working.
 int strange (int x, int y)
     {
      //Assuming x>0 and y>0
        if(x>=y)
         {
             x = x-y;
             return strange(x , y);
          }
        else
             return x;
      }
(i) What will the function strange(20,5) return ?                           [2]
(ii) What will the function strange(15,6) return ?                           [2]
(iii) In one line, state what the function is doing.  [1]
PART – II 
Answer seven questions in this part, choosing three questions from
Section A, two from Section B and two from Section C.
SECTION – A 
Answer any three questions.
Question 4  
(a) Given the Boolean function:
     F ( P, Q, R, S ) = ∑ ( 0, 1, 3, 4, 5, 6, 7, 9, 10, 11, 13, 15 )
Use Karnaugh’s map to reduce the function F, using  the SOP form.  Draw a logic gate diagram for the reduced SOP form.
You may use gates with more than two inputs.  Assume that the variable and their complements are available as inputs.   [5]
(b) Given  the Boolean function :
     X ( P, Q, R, S )  =  π ( 3, 8, 10, 12, 13, 14, 15 )
Use Karnaugh’s map to reduce this function X using the given POS form. Draw a logic gate diagram for the reduced POS form.
You may use gates with more than two inputs.  Assume that the variables and their complements are available as inputs.   [5]
Question 5  
The main safe in the nationalized bank can be opened by means of a unique password consisting of three parts.  Different parts of the  password are held by the
Chairman, Regional Manager, Bank Manager and Head cashier of the bank, respectively. In order to open the safe, any one of the following conditions must be
satisfied:
The password of the Chairman, together with passwords of any two other officials, must be entered.
OR
The password of all the three bank officials, excluding the chairman, must be entered.
The inputs are: 
        A :  Denotes the Chairman’s password.
        B :  Denotes the Regional Manager’s password.
        C :  Denotes the Bank Manager’s password.
        D : Denotes the Head Casher’s password.
Output: 
        X – Denotes that the safe can be opened.
               [1 indicates Yes and 0 indicates No in all cases]
(a)  Draw the truth table for the inputs and outputs given above and write the SOP expression for X( A, B, C, D ).    [5]
(b) Reduce  X( A, B, C, D ) using Karnaugh’s map, if possible. Draw the logic gate diagram
for the reduced SOP expression for X( A, B, C, D ) using AND  & OR gates.  You may use
gates with two or more inputs.  Assume that the variables and their complements are
available as inputs.  [5]
Question  6 
(a) Draw the truth table and logic circuit diagram for a Decimal to Binary Encoder.  [5]
(b)  Given :  F(x, y, z) = ∑ (1,3,7)  Verify :   F(x, y, z) = π (0,2,4,5,6)     [2]
(c)  Simplify the following expression by using Boolean laws. Show the working and also mention the laws used :
           X’Y’Z’ + XYZ’ + XY’Z’ + X’YZ’       [3]
Question 7 
(a)  Define Cardinal Form of an expression and Canonical Form of  an expression.  Give an example for each.  [3]
(b)  Which gate is equivalent to :          (NOR) OR (XOR)      [3]
(c)  Define a Half Adder.  Draw the Truth Table and Logic diagram of a Half Adder.  [4]
     
 SECTIO N– B 
Answer any two questions.
Each program should be written in such a way that it clearly depicts the logic of the problem.
This can be achieved by using mnemonic names and comments in the program.
    (Flowcharts and Algorithms are not required.)
The programs must be written in Java.
Question 8    
 A perfect square is an integer which is the square of another integer.  For example, 4, 9, 16 .. are perfect squares. Design a Class Perfect with the following description:   [10]
Class name :  Perfect
Data members/instance variables   
 n : stores an integer number
Member functions:  
 Perfect( ) : default constructor
 Perfect(int) : parameterized constructor to assign a value to ‘n’
 void perfect_sq() : to display the first 5 perfect squares larger than ‘n’ (if  n = 15, the next 3 perfect squares are 16, 25, 36)
 void sum_of() : to display all combinations of consecutive integers whose sum is equal to n. ( the number n = 15 can be expressed as
        1      2     3      4     5
        4      5     6
        7      8
Specify  the  class  Perfect  giving details of the constructors, void perfect_sq( ) and void sum_of().  Also define the main function to create an object and call methods
accordingly to enable the task.
Question 9 
A class RecFact defines a recursive function to find the factorial of a  number.  The details of the class are given below:  [10]
Class name :  RecFact
Data members/instance variables   
 n : stores the number whose factorial is required.
 r : stores an integer
Member functions :  
 RecFact( ) : default constructor
 void readnum( ) : to enter values for ‘n’ and ‘r’
 int factorial(int) : returns the factorial of the  number using the Recursive Technique.
 Void factseries(  )   : to calculate and display the value of  n! /  r!*(n-r )!
Specify the class RecFact  giving the details of the  constructor and member functions void readnum( ), int factorial(int) and void factseries( ).  Also define the main function
to create an object and call methods accordingly to enable the task.
Question 10 
In “Piglatin” a word such as  KING is replaced by INGKAY , while TROUBLE becomes OUBLETRAY and so on . The first vowel of the original word becomes
the start of the translation, any  preceding letters being shifted towards the end and followed by AY.  Words that begin with a vowel or which do not contain
any vowel are left unchanged. Design a class  Piglatin using the description of the data members and member functions given below:   [10]
Class name                                                 :    Piglatin
Data members /instance variables  : 
       Txt                                                  :   to store a word
       len                                                   :   to store the length
Member functions : 
     Piglatin( )                                          :   constructor to initialize the data mrmbers
     void readstring( )                              :   to  accept the word input in UPPER CASE
     void convert ( )                                 :   converts  the word into its  piglatin form
 and displays the word  (changed or unchanged)
     void  consonant( )                             :   counts and displays the number of
consonants present in  the given word.
Specify the class  Piglatin  giving the details of the constructor, void readstring( ), void convert( ) and void consonant( ).   Also define the main function to create an
object and call methods accordingly to enable the task.
SECTIO N– C 
Answer any two questions.
Each program should be written in such a way that it clearly depicts the logic of the problem
stepwise.
This can be achieved by using comments in the program and mnemonic names or
pseudo codes for algorithms.  The programs must be written in Java and the algorithms must be
written in general / standard form, wherever required / specified.
 (Flowcharts are not required.)
Question 11  
A class Author contains details of the author and another class Book List contains details of the books written by him.  The details of the two classes are given below:   [10]
Class name :  Author
Data members   
 authorno : stores the author’s number
 name : stores the author’s name
Member functions  
 Author ( ) : default constructor
 Author ( … ) : parameterised  constructor to assign values to author number and name
 void show( ) : to display the author’s details
Class name :  Booklist
Data members/instance variables   
 bookno : Long type variable to the store book number
bookname : stores the book name
price : float variable to store the price
 edition : integer type variable to store the edition number
Member functions
 Booklist (…) :  parameterized constructor to assign values to data members of both the classes
void show( ) : to display all the details
Specify the class  Author giving details of the  constructors and member function  void show( ).  Using the concept of Inheritance, specify the class Booklist giving details of the
constructor and the member function  void show( ). Also define the main function to create an object and call methods accordingly to enable the task.
Question 12 
In a computer game, a vertical column and a pile of rings are displayed.  The objective of the game is to pile up rings on the column till it is full.  It can hold 10 rings at the
most.  Once the column is full, the rings have to be removed from the top till the column is empty and then the game is over.  Define the class RingGame with the following
details:   [10]
Class name :  RingGame
Data members/instance variables   
 ring [ ] : array to hold rings (integer)
 max : integer to hold maximum capacity of ring array
 upper : integer to point to the upper most element
Member functions
 RingGame(int m) : constructor to initialize, max = m & upper to – 1.
 void jump-in(int ) : adds a ring to the top of the column, if possible. otherwise,
displays a message “Column full. Start removing rings”.
 void jump-out( ) : removes the ring from the top, if column is not empty.  otherwise,
outputs a message, “Congratulations. The game is Over”.
Specify the class  RingGame giving the details of the  constructor and functions  void jump-in(int) and void jump-out( ).  Also define the main function to create an object and
call methods accordingly to enable the task.
Question 13 
(a) A Linked List is formed from the objects of the class,
                        Class Node
                             {
                                 int num;
                                 Node next;
                              }
Write the algorithm OR a method for inserting a node in the end of the list. The method declaration is given below :
  void insertnode(Node start)   [4]
(b) State the complexity for the following algorithms :  [3]
 (i) Linear Search
 (ii) Binary Search
 (iii) Selection Sort
(c)  List the nodes  in the tree given below using:   [3]
 (i) Preorder Traversal
 (ii) Postorder Traversal
 (iii) Inorder traversal
F
H
M
N
G
I
K
J P
O
L

ISC Practical Paper – 2012 (Solved)

January 22, 2013 17 comments

COMPUTER SCIENCE

Paper – 2

(PRACTICAL)

(Reading Time: 15 minutes)

 (Planning Session AND Examination Session: Three Hours)

————————————————————————————————————

The total time to be spent on the Planning and the Examination Session is Three hours.

After completing the Planning Session, the candidate may begin with the Examination Session.

A maximum of 90 minutes is permitted to begin the Examination Session.

(Maximum Marks: 80)

————————————————————————————————————

As it is a practical examination the candidate is expected to do the following:

  1. Write an algorithm for the selected problem.    [10]
  2. Algorithm should be expressed clearly using ay standard scheme such as pseudo code or in steps which are simple enough to be obviously computable.
  3. Write a program in JAVA language. The program should follow the algorithm and should             [20]
    be logically and syntactically correct.
  4. Document the program using mnemonic names / comments, identifying and clearly                        [10]
    describing the choice of data types and meaning of variables.
  5. Code / Type the program on the computer and get a printout (hard copy). Typically this                 [10]
    should be a program that compiles and runs correctly.
  6. Test run the program on the computer using the given sample data and get a printout of                 [20]
    the output in the format specified in the problem.
  7. Viva-Voce on the Selected Problem.     [20]

 Solve any one of the following Problems:

 Question 1.

A prime palindrome integer is a positive integer (without leading zeros) which is prime as well as a palindrome. Given two positive integers m and n, where m<= n, write a program to determine how many prime-palindrome integers are there in the range between m and n (both inclusive) and output them.

The input contains two positive integers m and n where m>=100 and n<= 3000. Display number of prime palindrome integers in the specified range along with their values in the format specified below:

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

Example 1:

INPUT:

M=100

N=1000

OUTPUT: The prime palindrome integers are:

101,131,151,181,191,313,351,373,383,727,757,787,797,919,929

Frequency of prime palindrome integers: 15

Example 2:

INPUT:

M=100

N=5000

OUTPUT: Out of Range

import java.io.*;

class PrimePal
{
    public void showPrimePal() throws IOException
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        int m,n, c=0;
        System.out.println(“Enter the Lower Limit:”);
        m=Integer.parseInt(br.readLine());
        System.out.println(“Enter the Upper Limit:”);
        n=Integer.parseInt(br.readLine());
        if(m>n || n>3000)
            System.out.println(“Out of Range.”);
        else
        {
            System.out.println(“The Prime Palindrome integers are:”);
            while(m<=n)
            {
                if(checkPrimePal(m))
                {
                    if(c==0)
                        System.out.print(m);
                    else
                        System.out.print(“, “+m);
                    c++;
                }
                m++;
            }
            System.out.println(“\nFrequency of Prime Palindrome integers: “+c);
        }
    }
    boolean checkPrimePal(int x)
    {
        boolean flag=false;
        int c=0, temp=x;
        int rev=0,rem=0;
        for(int i=1;i<=x;i++)
        {
            if(x%i==0)
                c++;
        }
        if(c<=2)
        {
            while(x!=0)
            {
                rem=x%10;
                rev=rev*10+rem;
                x/=10;
            }
            if(rev==temp)
                flag=true;
        }
        return flag;
    }
    public static void main(String args[]) throws IOException
    {
        PrimePal ob=new PrimePal ();
        ob.showPrimePal();
    }
}

Question 2.

 Write a program to accept a sentence as input. The words in the string are to be separated by a blank. Each word must be in upper case. The sentence is terminated by either “.”,”!” or “?”. Perform the following tasks:

(i)  Obtain the length of the sentence. (measured in words)

(ii) Arrange the sentence in alphabetical order of the words.

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

Example 1:

INPUT: NECESSITY IS THE MOTHER OF INVENTION.

OUTPUT:

Length: 6

Rearranged Sentence:

INVENTION IS MOTHER NECESSITY OF THE

Example 2:

INPUT: BE GOOD TO OTHERS.

OUTPUT:

Length: 4

Rearranged Sentence: BE GOOD OTHERS TO

import java.io.*;
class WordsInSentence
{
    public void take() throws IOException
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        String str, words[], stk=””;
        int i,j,c=0,flag, len;
        char ch;
        while(true)
        {
            flag=0;
            System.out.println(“Enter the sentence:”);
            str=br.readLine();
            len= str.length();
            words=new String[len];
            for(i=0;i
            {
                if(Character.isLowerCase(str.charAt(i)))
                {
                    flag=1;
                    break;
                }
            }
            if (flag==0)
                break;
            else
                System.out.println(“Enter the sentence again with all uppercase letters”);
        }
        i=0;
        while(i<len)
        {
            ch=str.charAt(i);
            if(ch==’ ‘|| ch==’.’ || ch==’?’ || ch==’!’)
            {
                words[c]=stk;
                c++;
                i++;
                stk=””;
            }
            else
            {
                stk+=ch;
                i++;
            }
        }
        for(i=0;i<c;i++)
        {
            for(j=0;j<c-1;j++)
            {
                if((words[j].compareTo(words[j+1]))>0)
                {
                    stk=words[j];
                    words[j]=words[j+1];
                    words[j+1]=stk;
                }
            }
        }
        System.out.println(“Length= “+c);
        System.out.println(“\nRearranged Sentence:\n”);
        for(i=0;i<c;i++)
            System.out.print(words[i]+” “);
    }
    public static void main(String args[]) throws IOException
    {
        WordsInSentence ob=new WordsInSentence();
        ob.take();
    }
}

Question 3.

Write a program to declare a matrix A [][] of order (MXN) where ‘M’ is the number of rows and ‘N’ is the number of columns such that both M and N must be greater than 2 and less than 20. Allow the user to input integers into this matrix. Perform the following tasks on the matrix:

  1. Display the input matrix
  2. Find the maximum and minimum value in the matrix and display them along with their position.
  3. Sort the elements of the matrix in ascending order using any standard sorting technique and rearrange them in the matrix.
  4. Output the rearranged matrix.

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

Example 1.

INPUT:

M=3

N=4

Entered values: 8,7,9,3,-2,0,4,5,1,3,6,-4

 OUTPUT:

Original matrix:

8  7  9  3

-2  0  4  5

1  3  6  -4

Largest Number: 9

Row: 0

Column: 2

Smallest Number: -4

Row=2

Column=3

Rearranged matrix:

-4  -2  0  1

3  3  4  5

6  7  8  9

 

import java.io.*;

class Matrix
{
public void take()throws Exception
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int arr[][],m,n;
int g,h,i,j,max,min,maxr,maxc,minr,minc;

while(true)
{
System.out.println(“\nEnter the number of rows :”);
m=Integer.parseInt(br.readLine());
System.out.println(“\nEnter the number of columns:”);
n=Integer.parseInt(br.readLine());
if(m<2 || n<2 || m>20 || n>20)
System.out.println(“\nEnter the number of rows and columns”);
else
break;
}
arr=new int[m][n];
for(i=0;i<m; i++)
{
for(j=0;j<n;j++)
{
System.out.println(“\nEnter Value:”);
arr[i][j]=Integer.parseInt(br.readLine());
}
}
max=arr[0][0];
min=arr[0][0];
maxr=0;
minr=0;
maxc=0;
minc=0;
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
if(arr[i][j]>max)
{
max=arr[i][j];
maxr=i;
maxc=j;
}
else if(arr[i][j]< min)
{
minr=i;
minc=j;
min=arr[i][j];
}
}
}
System.out.println(“\nOriginal Matrix\n”);
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
System.out.print(arr[i][j]+” “);
}
System.out.println();
}

System.out.println(“\nMaximum Value=”+max);
System.out.println(“\nRow=”+maxr);
System.out.println(“\nColumn=”+maxc);
System.out.println(“\nMinimum Value=”+min);
System.out.println(“\nRow=”+minr);
System.out.println(“\nColumn=”+minc);

for(g=0;g<m;g++)
{
for(h=0;h<n;h++)
{
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
if(arr[g][h]< arr[i][j])
{
min=arr[g][h];
arr[g][h]=arr[i][j];
arr[i][j]=min;
}
}
}
}
}
System.out.println(“\nSorted Array\n”);
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
System.out.print(arr[i][j]+” “);
}
System.out.println();
}

}
public static void main(String args[]) throws Exception
{
Matrix ob=new Matrix();
ob.take();
}
}

You may like to see these papers .

Follow

Get every new post delivered to your Inbox.

Join 200 other followers

%d bloggers like this: