Navbar

Wednesday, 29 April 2020

ISC COMPUTER PRACTICAL - 2020 - QUESTION 3 (String Program)

ISC 2020 Computer Practical Question 3 –  String program.


-WRITTEN BY CODERGURUJI


























  Solution :


import java.util.*;
class Program3
{
public static void main(String rags[])
{
    String x="",x1="";
    int s=0,p=0,h=0,w=0,m=0;
    Scanner sc=new Scanner(System.in);
    System.out.println("Enter Any Sentence");
    String n=sc.nextLine().trim();
    n=n+" ";
    x1=n;
    int b[]=new int[1000];
    String a[]=new String[1000];
    String c[]=new String[1000];
    int l=x1.length();
    char ch1=x1.charAt(l-1);
    if(n.charAt(l-2)!='.')
    { 
        System.out.print("INVALID");
    }
    else
    {
        System.out.println(n);              /// for printing original Sentence
        n=n.substring(0,n.length()-2)+" ";
    for(int i=0;i<l-1;i++)
    {
        char ch=n.charAt(i);
        if(ch!=' ')
        {
            x=x+ch;
        }
        else
        {
            int q=x.length();     
            b[s]=q;         // for storing length of each word in array              
            s++;
            
            a[p]=x;                  // for storing each word in array
            p++;
            x="";  
        }
    }

      // sorting of the sentence}

    for(int i=0;i<s;i++)
    {
        for(int j=0;j<s-i-1;j++)
        {
            if(b[j]>b[j+1])
            {
                int temp=b[j];
                b[j]=b[j+1];
                b[j+1]=temp;
                
                String temp1=a[j];
                a[j]=a[j+1];
                a[j+1]=temp1;
            }
        }
    }   
      for(int i=0;i<s;i++)
       {
        m=b[i]; 
        int r1=0;
        if(b[i]!=b[i+1])             
        {
            System.out.print(a[i]+" ");       //for print sentence whose length is                                                                                                                                     not equal.
        }
        else
        {
             for(int j=i;j<s;j++)
            {
                c[r1]=a[j];
                r1++;
            }
            for(int k=0;k<r1;k++)
            {
                for(int j=0;j<r1-k-1;j++)
                {
                    if(c[j].compareTo(c[j+1])>0)    // sorting the word                                                                                                                           whose length is same
                    {
                        String temp=c[j];
                        c[j]=c[j+1];
                        c[j+1]=temp;
                    }
                }
            }
            for(int j=0;j<r1;j++)
            {
                System.out.print(c[j]+" ");
            }
            i=i+r1-1;
        }
    }
}
}
}

------------------------------------end-------------------------------------------

Thursday, 2 April 2020

ISC COMPUTER PRACTICAL - 2020 - QUESTION 2 (Matrix Program)

ISC 2020 Computer Practical Question 2–Matrix program.

-WRITTEN BY CODERGURUJI









Solutions:


 import java.util.*;
class coderguruji
{
public static void main(String args[])
{
double d=0.0;
Scanner sc=new Scanner(System.in);
System.out.println("enter m*n");
int p=0,q=0,x=0,s=0,y=1;
int m=sc.nextInt();
int n=sc.nextInt();
if((m<0||m>10)&&(n<2||n>6))
{
System.out.println("OUT OF RANGE");
}
else
{
int a[][]=new int[m][n];
int b[]=new int[1000];
int c[]=new int[1000];
for(int i=0;i<m;i++)
{
for(int j=0;j<n;j++)
{
a[i][j]=sc.nextInt();
}
}
for(int i=0;i<m;i++)
{
for(int j=0;j<n;j++)
{
b[p]=a[i][j];
p++;
}
}
for(int i=0;i<m;i++)
{
for(int j=0;j<n;j++)
{
d=a[i][j]*Math.pow(8,n-y);
s=(int)d;
x=x+s;
y++;
}
c[q]=x;
q++;
y=1;
x=0;
}
System.out.println("FILLED MATRIX"+"\t\t"+"DECIMAL EQU");

for(int i=0;i<m;i++)
{
for(int j=0;j<n;j++)
{
System.out.print(a[i][j]+" ");
}
System.out.println();
}
for(int j=0;j<q;j++)
{
System.out.print("\t\t\t"+c[j]);
System.out.println();
}
}
}
}
---------------------------end-------------------------------

Saturday, 28 March 2020

ISC COMPUTER PRACTICAL - 2020 - QUESTION 1 (PRIME ADAM NUMBER)

ISC 2020 Computer Practical Question 1–Prime Adam Integer.

-WRITTEN BY CODERGURUJI

Prime-Adam integer is a positive integer (without leading zeroes) which is a prime as well as an Adam number.
Prime number: A number which has only two factors, i.e. 1 and the number itself. Example: 2, 3, 5, 7, etc.
Adam number: The square of a number and the square of its reverse are reverse to each other. Example: If n = 13 and reverse of ‘n’ is 31, then, 132 = 169, and 312 = 961 which is reverse of 169. Thus, 13 is an Adam number.
Accept two positive integers m and n, where m is less than n as user input. Display all Prime-Adam integers that are in the range between m and n (both inclusive) and output them along with the frequency, in the format given below:
Test your program with the following data and some random data:
Example 1:

INPUT:

m = 5
n = 100

OUTPUT:

The Prime-Adam integers are:
11, 13, 31
Frequency of Prime-Adam integers is: 3
Example 2:

INPUT:

m = 100
n = 200

OUTPUT:

The Prime-Adam integers are:
101, 103, 113
Frequency of Prime-Adam integers is: 3
Example 3:

INPUT:

m = 50
n = 70
OUTPUT:
The Prime-Adam integers are:
NIL
Frequency of Prime-Adam integers is: 0
Example 4:

INPUT:

m = 700
n = 450
OUTPUT:
Invalid Input.

SOLUTIONS :

import java.util.*;
class coderguruji
{
    public static void main(String coderguruji[])
    {      
        int p=0,p1=0,c=0,s=0,d=0,s1=0,f=0;
        Scanner sc=new Scanner(System.in);
        System.out.println("enter M and N");
        int m=sc.nextInt();
        int n=sc.nextInt();
        if(m>n)
        {
            System.out.println("INVALID INPUT");
        }
        else
        {
        int a[]=new int[1000];
        int b[]=new int[1000];
        System.out.println("THE PRIME-ADAM INTEGERS ARE:");
        for(int i=m;i<n;i++)
        {
            for(int j=1;j<=i;j++)
            {
                if(i%j==0)           ///for finding prime number
                {
                    c++;
                }
            }
                if(c==2)
                {
                    a[p]=i;     ////storing all prime number in array
                    p++;
                    c=0;
                }
                else
                {
                    b[p1]=i;
                    p1++;
                    c=0;
                }
            }
        for(int i=0;i<p;i++)
            {
               int w=a[i];
                while(w>0)
                {
                    int b1=w%10;
                    s=s*10+b1;         ///for reversing prime numbers
                    w=w/10;
                   
                }
                d=a[i]*a[i];      ///Square of prime numbers
                int sum=s*s;      ///Square of reverse numbers
              int  sum1=sum;
                while(sum1>0)
                {
                    int b2=sum1%10;
                    s1=s1*10+b2;         ///reverse of Square of reversed numbers
                    sum1=sum1/10;
                   
            }
            if(d==s1)      ///checking numbers is prime adam number
             {
                 f++;
                System.out.println(a[i]+" ");     ///printing of prime adam number
                 d=0;
                s1=0;
                s=0;
            }
                else
                {
                d=0;
                s1=0;
                s=0;
            }
        }
        System.out.println("FREQUENCY OF PRIME-ADAM INTEGERS IS:"+f);
    }
}
            }
        -----------------------------------------end----------------------------------------------