Navbar

Tuesday, 2 April 2019

ISC 2015 Computer Practical Paper Solved

 ISC 2015 Computer Practical Paper  Solved

Question 1:

Given two positive numbers M and N, such that M is between 100 and 10000 and N is less than 100. Find the smallest integer that is greater than M and whose digits add up to N. For example, if M = 100 and N = 11, then the smallest integer greater than 100 whose digits add up to 11 is 119.

Write a program to accept the numbers M and N from the user and print the smallest required number whose sum of all its digits is equal to N. Also, print the total number of digits present in the required number. The program should check for the validity of the inputs and display an appropriate message for an invalid input.

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

Example 1

INPUT :
M = 100
N = 11

OUTPUT :
The required number = 119
Total number of digits = 3

Example 2

INPUT :
M = 1500
N = 25

OUTPUT :
The required number = 1699
Total number of digits = 4

Example 3

INPUT :
M = 99
N = 11

OUTPUT :
INVALID INPUT

Example 4

INPUT :
M = 112
N = 130

OUTPUT :
INVALID INPUT

Solution 1;
import java.util.*;
class Number
{
    int sumDig(long n)
    {
        int sum = 0, d;
        while(n>0)
        {
            d = (int)(n%10);
            sum = sum + d;
            n = n/10;
        }
        return sum;
    }
 
    int countDig(long n)
    {
        String s = Long.toString(n);
        int len = s.length();
        return len;
    }
 
    public static void main()throws Exception
    {
        question ob = new question();
        Scanner sc = new Scanner(System.in);
        System.out.print("Enter a value of 'm' from 100 to 10000 : ");
        int m = sc.nextInt();
        System.out.print("Enter a value of n from 1 to 99 : ");
        int n = sc.nextInt();
     
        if(m<100 || m>10000 || n<1 || n>99)
        {
            System.out.println("Invalid Input");
        }
        else
        {
            long i = (long)m;
            while(ob.sumDig(i)!=n)
            {
                i=i+1;
            }
            System.out.println("The required number = "+i);
            System.out.println("Total number of digits = "+ob.countDig(i));
        }
    }
}
Output 1:
Enter a value of ‘m’ from 100 to 10000 : 1500
Enter a value of ‘n’ from 1 to 99 : 25
The required number = 1699
Total number of digits = 4

Output 2:
Enter a value of ‘m’ from 100 to 10000 : 100
Enter a value of ‘n’ from 1 to 99 : 20
The required number = 299
Total number of digits = 3

Output 3:
Enter a value of ‘m’ from 100 to 10000 : 112
Enter a value of ‘n’ from 1 to 99 : 130
Invalid Input
------------end---------------------

Question 2:

Write a program to declare a square matrix A[ ][ ] of order MxM where ‘M’ is the number of rows and the number of columns, such that M must be greater than 2 and less than 10. Accept the value of M as user input. Display an appropriate message for an invalid input. Allow the user to input integers into this matrix. Perform the following tasks:

(a) Display the original matrix.
(b) Rotate the matrix 90° clockwise as shown below:
 Original matrix       Rotated matrix
   1 2 3                          7 4 1
   4 5 6                          8 5 2
   7 8 9                          9 6 3
(c) Find the sum of the elements of the four corners of the matrix.

Test your program for the following data and some random data:

Example 1

INPUT :

M = 3
   1 2 3
   4 5 6
   7 8 9

OUTPUT :

ORIGINAL MATRIX
    1 2 3
    4 5 6
    7 8 9
MATRIX AFTER ROTATION
     7 4 1
     8 5 2
     9 6 3
Sum of the corner elements = 20

Example 2

INPUT :

M = 3

 1 2 3
 4 5 6
 7 8 9

OUTPUT :

ORIGINAL MATRIX
  1 2 3
  4 5 6
  7 8 9

MATRIX AFTER ROTATION

  7 4 1
  8 5 2
  9 6 3
Sum of the corner elements = 18

Example 3

INPUT :
M = 14

OUTPUT :
SIZE OUT OF RANGE

Example 4

INPUT :
M = 112
N = 130

OUTPUT :
INVALID INPUT

Solution:

import java.util.*;
class mat
{
    public static void main(String args[])
    {
        Scanner sc=new Scanner(System.in);
        System.out.print("Enter the size of the matrix : ");
        int m=sc.nextInt();
        if(m<3 || m>9)
            System.out.println("Size Out Of Range");
        else
        {
            int A[][]=new int[m][m];

            /* Inputting the matrix */
            for(int i=0;i<m;i++)
            {
                for(int j=0;j<m;j++)
                {
                    System.out.print("Enter an element : ");
                    A[i][j]=sc.nextInt();
                }
            }
           
            /* Printing the original matrix */
            System.out.println("*************************");
            System.out.println("The Original Matrix is : ");
            for(int i=0;i<m;i++)
            {
                for(int j=0;j<m;j++)
                {
                    System.out.print(A[i][j]+"\t");
                }
                System.out.println();
            }
            System.out.println("*************************");
           
            int B[][]=new int[m][m];
            int x;
           
             /*Rotation of matrix begins here */
            for(int i=0;i<m;i++)
            {
                x = m-1;
                for(int j=0;j<m;j++)
                {
                    B[i][j]=A[x][i];
                    x--;
                }
            }
           
            /* Printing the rotated matrix */
            System.out.println("Matrix After Rotation is : ");
            for(int i=0;i<m;i++)
            {
                for(int j=0;j<m;j++)
                {
                    System.out.print(B[i][j]+"\t");
                }
                System.out.println();
            }
            System.out.println("*************************");

            int sum = A[0][0]+A[0][m-1]+A[m-1][0]+A[m-1][m-1];  // Finding sum of corner elements
            System.out.println("Sum of the corner elements = "+sum);
        }
    }
}

Output:

INPUT :
Enter the size of the matrix : 3

       1 2 3
       4 5 6
       7 8 9

Output:
The Original Matrix is :
1 2 4 9
2 5 8 3
1 6 7 4
3 7 6 5
*************************
Matrix After Rotation is :
3 1 2 1
7 6 5 2
6 7 8 4
5 4 3 9
*************************
Sum of the corner elements = 18

**********end*************


Question 3:

Write a program to accept a sentence which may be terminated by either ‘.’ or ‘?’ only. The words are to be separated by a single blank space. Print an error message if the input does not terminate with ‘.’ or ‘?’. You can assume that no word in the sentence exceeds 15 characters, so that you get a proper formatted output.

Perform the following tasks:
(i) Convert the first letter of each word to uppercase.
(ii) Find the number of vowels and consonants in each word and display them with proper headings along with the words.

Test your program with the following inputs.

Example 1

INPUT: Intelligence plus character is education.

OUTPUT:
Intelligence Plus Character Is Education

Word              Vowels           Consonants
Intelligence  5                              7
Plus                  1                              3
Character  3                              6
Is                  1                              1
Education          5                              4

Example 2

INPUT: God is great.

OUTPUT:
God is Great

 Word Vowels   Consonants
 God     1                 2
  Is             1                 1
 Great     2                 3

Example 3

INPUT: All the best!

OUTPUT:
Invalid Input.

Soluton :

import java.util.*;
class st
{
public static void main(String args[])
{
String p="";
int v=0,c=0;
Scanner sc=new Scanner(System.in);
System.out.println("Enter Sentence");
String n=sc.nextLine();
n=n+" ";
System.out.println("Word \t vowel \tconsonant");
int l=n.length();
if(n.charAt(l-2) != '.' && n.charAt(l-2) != '?')
        {
            System.out.println("Invalid Input. End a sentence with either '.' or '?'");
        }
else
{
for(int i=0;i<l;i++)
{
char ch=n.charAt(i);
if(ch!=' ')
p=p+ch;
else
{
int k=p.length();

for(int j=0;j<k;j++)
{
char ch1=p.charAt(j);
if(ch1=='.')
break;
if(ch1=='a'||ch1=='e'||ch1=='i'||ch1=='o'||ch1=='u')
{
v++;
}
else
c++;
}
System.out.println(p+"\t"+v+"\t"+c);
p="";
v=0;
c=0;
}
}
}
}
}
----------------end--------------------------

7 comments: