Full Range

Call me (USA Free)

Sunday, 24 August 2014

PROGRAMS FOR ISC PRACTICAL EXAM GUIDANCE

Leave a Comment
Q. Write a program in Java to input a number in decimal number system and convert it into
     its equivalent number in the Hexadecimal number system.Hexadecimal Number system is a number
    system which can represent a number in any other number system in terms of digits ranging from
    0 to 9 and then A-F only.This number system consists of only sixteen basic digits i.e. 0,1,
    2,3,4,5,6,7,8,9,A,B,C,D,E and F.Here 10 is represented as A,11 as B and so on till 15 which is
    represented as F.For example :47 in hexadecimal number system can be represented as 2F in the
    Hexadecimal number system.

 import java.io.*;
public class DecimalToHexa
 {
     public static void main(String args[])throws Exception
     {
         InputStreamReader isr =new InputStreamReader(System.in);
         BufferedReader stdin=new BufferedReader(isr);
         System.out.print("Enter the number in decimal number system:");
         int n=Integer.parseInt(stdin.readLine());
         int r;
         String s="";  //variable to store the result after
                       //sorting the digits as in hexadecimal number system
         char dig[]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
         while(n>0)
          {
              r=n%16;  //finding the remainder
              s=dig[r]+s; //adding the remainder to the result
              n=n/16;
          }
          System.out.print("Output="+s);
      }
 }
Read More

Friday, 9 May 2014

2012 ISC COMPUTER SCIENCE PRACTICAL SOLVED PAPER

2 comments

ISC Computer Science Practical 2012

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 < 3000 and n < 3000. Display the 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
solution
 
import java.io.*;

public class PrimePalindrome

 {

     public static void main(String args[])throws Exception

      {

          BufferedReader stdin=new BufferedReader(new InputStreamReader(System.in));

          System.out.print("Enter the lower limit:");

          int m=Integer.parseInt(stdin.readLine());

          System.out.print("Enter the upper limit:");

          int n=Integer.parseInt(stdin.readLine());

          int count=0,flag;

          int i2;//stores the value of i to i2

          int r;//stores the reversed number

          if(m<n)//checks whether lower limit less than upper limit

            {

                if((m<3000)&&(n<3000))

                 {

                    System.out.println("The prime palindrome integers are:");

                     for(int i=m;i<=n;i++)

                      {

                         flag=0;

                         for(int j=2;j<i;j++)//checks whether the number is prime

                          {

                              if(i%j==0)

                               {

                                   flag=1;

                                   break;

                               }

                           }

                              i2=i;r=0;

                            while(i2>0)//reverses the number

                               {

                                r=(r*10)+(i2%10);

                                i2=i2/10;

                               }

                            if((flag==0)&&(r==i))

                             {

                                 if(count>0)//to avoid comma(,) after the last number

                                  System.out.print(",");

                                 System.out.print(i);

                                 count++;

                              }

                        }

                        System.out.println();

                        System.out.println("Frequency of prime palindrome integers:"+count);  

                   }

                 else

                  System.out.println("Out of range");

            }

 

        }

    }                      

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:

1. Obtain the length of the sentence (measured in words)
2. 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
solution
import java.io.*;

public class SenAlpha
 {

     public static void main(String args[])throws Exception

      {

          BufferedReader stdin=new BufferedReader(new InputStreamReader(System.in));

          System.out.print("Enter the sentence:");

          String s=stdin.readLine();

           s=s.toUpperCase();//converts the sentence to uppercase.

           int l=s.length();

           char c=s.charAt(l-1);//extracts the last character

           char ch;

           int pos=0,length=0,w=0;

           String temp;

           if(c=='.'||c=='!'||c=='?')

            {

              

              for(int i=0;i<l;i++) //computes the length of the sentence(in words)

               {

                 ch=s.charAt(i);

                 if(ch==' '||ch==c)

                   length++;

               }

                System.out.println("Length:"+length);

                String word[]= new String[length]; 

                for(int j=0;j<l;j++) //to store each word in array

                  {

                    ch=s.charAt(j);

                     if(ch==' '||ch==c)

                      {

                        word[w]=s.substring(pos,j);

                        w++;

                        pos=j+1;

                       }

                   }

                     for(int k=0;k<length;k++)//arranges the word in alphabhetical order

                       for(int m=0;m<(length-k-1);m++)

                        {

                            if(word[m].compareTo(word[m+1])>0)

                             {

                               temp=word[m];

                               word[m]=word[m+1];

                               word[m+1]=temp;

                              }

                        }

                   System.out.print("Rearranged Sentence:");

                    for(int r=0;r<length;r++)//prints the rearranged sentence

                      System.out.print(word[r]+" "); 

             }       

         else

           System.out.print("Invalid input");

            }         

                  

     } 
 
 

 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.

Output the rearranged matrix.

Sample input Output
INPUT:
M=3
N=4
Entered values: 8,7,9,3,-2,0,4,5,1,3,6,-4
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 

solution
import java.io.*;

public class Matrix
{

    public static void main(String args[])throws Exception

    {

        BufferedReader stdin=new BufferedReader(new InputStreamReader(System.in));

        System.out.print("Enter the number of rows:");

        int M=Integer.parseInt(stdin.readLine());

        System.out.print("Enter the number of columns:");

        int N=Integer.parseInt(stdin.readLine());

        int large,small;

        int lrow=0,srow=0;

        int lcol=0,scol=0;

        int i=0,j=0,temp;

         if(2<M&&M<20&&2<N&&N<20)

        {

            int num[][] = new int[M][N];

            System.out.print("Enter the numbers:");

            for( i=0;i<M;i++)//to enter the elements

                for( j=0;j<N;j++)

                  num[i][j]=Integer.parseInt(stdin.readLine());

             System.out.println("Original matrix:");  

             large=num[0][0];

             small=num[0][0];

             for( i=0;i<M;i++) //to diplay matrix and find largest ad smallest number

              { 

               for(j=0;j<N;j++)

                 {   

                    System.out.print(num[i][j]+" ");

                     if(num[i][j]>large)

                       {

                        large=num[i][j];

                        lrow=i;

                        lcol=j;

                       }

                         if(num[i][j]<small)

                         {

                           small=num[i][j];

                           srow=i;

                           scol=j;

                         }  

                  }

                System.out.println(); 

               }

           System.out.println("Largest number:"+large);

           System.out.println("row="+lrow);

           System.out.println("column="+lcol);

           System.out.println("Smallest number:"+small);

           System.out.println("row="+srow);

           System.out.println("column="+scol); 

           int num1[]=new int[M*N];

           int s=0;

           for(i=0;i<M;i++)//storing the elements into single dimensional array

             for(j=0;j<N;j++)

              {  

              num1[s]=num[i][j];

              s++;

             }

               for(i=0;i<(M*N);i++) //sorting using bubble sort

                for(j=0;j<((M*N)-i-1);j++)

                 {

                     if(num1[j]>num1[j+1])

                      {

                          temp=num1[j];

                          num1[j]=num1[j+1];

                          num1[j+1]=temp;

                       }

                   }

                  System.out.println("Rearraged matrix:");      

                  s=0;

                 for(i=0;i<M;i++)//storing the elements  back to double dimensional and printing

                 { 

                   for(j=0;j<N;j++)

                     {  

                     num[i][j]=num1[s];

                     System.out.print(num[i][j]+" ");

                     s++;

                     } 

                   System.out.println();

                }

        }

        else

          System.out.println("Out of range");

   }                     

}                          

                          

                          

                          
Read More

Monday, 14 April 2014

String programs.....

1 comment
Q.Write a java program to count the number of words in the entered sentence

 import java.io.*;
public class CountWords
{
  public static void main(String args[])throws Exception
    {
       BufferedReader stdin =new BufferedReader(new InputStreamReader(System.in));
       System.out.print("Enter the sentence: ");
       String s=stdin.readLine();
       s=' '+s;
       char ch;
       int w=0;
       for(int i=0;i<s.length();i++) //loop is used to extract each character in the sentence
        {
           ch=s.charAt(i);
           if(ch==' ')
            {
             w++;
            }
        }
     System.out.println("Number of word in the sentence:"+w);
    } //method
} //class


Q.Write a program to accept a word and  arrange the letters of words in alphabetical order
    Sample input: computer
                output:cemoprtu

import java.io.*;
public class WordAlbha
 {
     public static void main(String args[])throws Exception
     {
         InputStreamReader isr =new InputStreamReader(System.in);
         BufferedReader stdin=new BufferedReader(isr);
         System.out.print("Enter the word:");
         String word=stdin.readLine();
         char ch;
         for(int i=65;i<=90;i++)
          {
              for(int j=0;j<word.length();j++)
               {
                   ch=word.charAt(j);
                   ch=Character.toLowerCase(ch);
                   if(ch==(char)i||ch==(char)(i+32))
                   System.out.print(ch);
                }
           }
        }
    }    

Read More

Printing Patterns....

Leave a Comment
Q.Write a program to print the following pattern
  
    *
     * *
     * * *
     * * * *
     * * * * *       

public class HalfTriangle
 {
     public void pattern(int n)
      {
          for(int i=1;i<=n;i++) //to define the number of rows
            {
              for(int j=1;j<=i;j++)
               {
                  System.out.print("* ");
                }
             System.out.println();
            }
      } //method
  } //class
Read More

Simple programs for beginner's

Leave a Comment

Q.Write a java program to add two numbers.

     public class  addNum
    {
        public void sum(int x,int y) // creates the instance of a class
       {
   
           int z=x+y;
           System.out.print(z);
       }
 
   }
 
  Q.Write a java program to subtract two numbers.

      public class Difference
       {
           public void diff(int x,int y)
            {
              int z=x-y;
              System.out.println("The difference between "+x+" and "+y+" is "+z);
            }
      }
 Q.Write a java program to check whether the entered number is prime or composite...
     
      import java.io.*;
     public class Prime
    {
         public static void main(String args[])throws Exception
          {
             BufferedReader stdin =new BufferedReader(new InputStreamReader(System.in));
             System.out.print("Enter the number: ");
             int n=Integer.parseInt(stdin.readLine());
             int flag=0;
              for(int i=2;i<n;i++) //used to get the vales less than the entered number in loop
               {
                   if(n%i==0) //checks if the number is divisble by i
                    {
                       flag=1;
                       break; //exits from the loop
                    }
       
               }
               if(flag==0)
               {
                  System.out.println(n+" is a prime number");
               }
             else
             {
                System.out.println(n+" is a composite number");
            }
    } //method
} //class

Q.Write a java program to reverse the entered number

    import java.io.*;
   public class Reverse
    {
        public static void main(String args[])throws Exception
        {
          BufferedReader stdin =new BufferedReader(new InputStreamReader(System.in));
          System.out.print("Enter the number: ");
          int n=Integer.parseInt(stdin.readLine());
          int nr=0;
         while(n>0) //loop used to reverse the number
         {
          nr=(nr*10)+(n%10); //(n%10):extracts the last digit of the number
          n=n/10;
         }
         System.out.print(nr);
      } //method
 } //class

Read More
Leave a Comment
This blog is mainly a guide for isc computer science students...Some solved questions are given in this blog and also guidance to java progaram....icse students can also refer to this site for learning programs.

Read More