Thursday, 27 October 2016

ISC Computer 2013 Theory Part II : Section B Fully Solved



Section B : 2013 Solved Theory


Question :8
Emirp Number Using recursive technique.
Sample Input : 13
13 and 31 both are prime number.
Sample Output : 13 is a Emirp Number.
import java.util.*;
public class Emirp
{
intn,rev,f;
Emirp(intnn)
    {
        n=nn;
        rev=0;
        f=2;
    }
intisPrime(int x)
    {
        if(f==x)
        {
            return (1);
        }
        else if(x%f++==0)
        {
            return (0);
        }
        else
        {
            return (isPrime(x));
        }
    }
    void isEmirp()
    {
intt,r;
        t=n;
for(;t!=0;)
        {
            r=t%10;
            rev=rev*10+r;
            t=t/10;
        }
        if((isPrime(n)==1)&&(isPrime(rev)==1))
        {
System.out.println(n+" is a Emirp Number.");
        }
        else
        {
System.out.println(n+" is not a Emirp Number.");
        }
    }
    public static void main()
    {
        Scanner in=new Scanner(System.in);
int no;
System.out.println("Enter a number to check if it is EmirpNumber : ");
        no=in.nextInt();
Emirpob=new Emirp(no);
ob.isEmirp();
    }
 


Question : 9
Design a class Exchange…………terminated by full stop.
Sample Input : It is a warm day
Sample Output :tIsi a marwyad
import java.util.*;
public class Exchange
{
    String sent,rev;
int size;
Exchange()
    {
        sent="";
        rev="";
        size=0;
    }
    void readsentence()
    {
        Scanner in=new Scanner(System.in);
System.out.println("Enter your sentance : ");
        sent=in.nextLine();
    }
    void exfirstlast()
    {
        String w[];
inti,j;
        w=sent.split(" ");
        String r[]=new String[w.length];
        for(i=0;i<r.length;i++)
        {
            r[i]="";
        }
        for(i=0;i<w.length;i++)
        {
            for(j=0;j<w[i].length();j++)
            {
                if(j==0)
                {
                    r[i]=r[i]+w[i].charAt(w[i].length()-1);
                }
                else if(j==(w[i].length()-1))
                {
                    r[i]=r[i]+w[i].charAt(0);
                }
                else
                {
                    r[i]=r[i]+w[i].charAt(j);
                }
            }
            rev=rev+r[i]+" ";
        }
    }
    void display()
    {
System.out.println("Original Sentence : "+sent);
System.out.println("Changed Sentence : "+rev);
    }
    public static void main()
    {
        Exchange ob=new Exchange();
ob.readsentence();
ob.exfirstlast();
ob.display();
    }
}


Question : 10
A class Matrix contains a two ………………..enable the task.
Sample Input :6      5      4                 9     8      7
                           3      2      1     and     5      6     4
                         3      5      2                6      7     3
Sample Output :3      3      3
                              2      4      3
                              3      2      1
import java.util.*;
public class Matrix
{
intarr[][]=new int[25][25];
intm,n;
Matrix(intmm,intnn)
    {
        m=mm;
        n=nn;
    }
    void fillarray()
    {
        Scanner in=new Scanner(System.in);
inti,j;
System.out.println("Enter the elements in the matrix : ");
        for(i=0;i<m;i++)
        {
System.out.println("Enter "+n+" elements in row "+(i+1)+" : ");
            for(j=0;j<n;j++)
            {
arr[i][j]=in.nextInt();
            }
        }
System.out.println("Matrix Formed");
        for(i=0;i<m;i++)
        {
            for(j=0;j<n;j++)
            {
System.out.print(arr[i][j]+"\t");
            }
System.out.println();
        }
    }
    Matrix subMat(Matrix A)
    {
        Matrix B=new Matrix(m,n);
inti,j;
        for(i=0;i<m;i++)
        {
            for(j=0;j<n;j++)
            {
B.arr[i][j]=A.arr[i][j]-arr[i][j];
            }
        }
        return (B);
    }
    void display()
    {
inti,j;
System.out.println("Subtracted Matrix");
        for(i=0;i<m;i++)
        {
            for(j=0;j<n;j++)
            {
System.out.print(arr[i][j]+"\t");
            }
System.out.println();
        }
    }
    public static void main()
    {
        Scanner in=new Scanner(System.in);
intr,c;
System.out.println("Enter number of rows : ");
        r=in.nextInt();
System.out.println("Enter number of columns : ");
        c=in.nextInt();
        Matrix ob=new Matrix(r,c);
        Matrix ob1=new Matrix(r,c);
        Matrix ob2=new Matrix(r,c);
ob.fillarray();
        ob1.fillarray();
        ob2=ob.subMat(ob1);
        ob2.display();
    }
}  

No comments:

Post a Comment