Showing posts with label ISC JAVA PROGRAMS. Show all posts
Showing posts with label ISC JAVA PROGRAMS. Show all posts

Monday, 18 February 2019

Goldbach Number ISC 2018

Question: A Goldbach number is a positive even integer that can be expressed as the sum of two odd primes.
Note: All even integer numbers greater than 4 are Goldbach numbers.
Example:
6 = 3 + 3
10 = 3 + 7
10 = 5 + 5
Hence, 6 has one odd prime pair 3 and 3. Similarly, 10 has two odd prime pairs, i.e. 3, 7 and 5, 5.
Write a program to accept an even integer ‘N’ where N > 9 and N < 50. Find all the odd prime pairs whose sum is equal to the number ‘N’.
Test your program with the following data and some random data:
Example 1:
INPUT:
N = 14
OUTPUT:
Prime pairs are:
3, 11
7, 7
Example 2:
INPUT:
N = 30
OUTPUT:
Prime numbers are:
7, 23
11, 19
13, 17
Example 3:
INPUT:
N = 17
OUTPUT:
Invalid input. Number is odd.
Example 4:
INPUT:
N = 126
OUTPUT:
Invalid input. Number is out of range.


Friday, 15 February 2019

Quiz ISC17

Question:
The result of a quiz competition is to be prepared as follows:
The quiz has five questions with four multiple choices (A, B, C, D), with each question carrying 1 mark for the correct answer. Design a program to accept the number of participants N such that N must be greater than 3 and less than 11. Create a double dimensional array of size (Nx5) to store the answers of each participant row-wise.
Calculate the marks for each participant by matching the correct answer stored in a single dimensional array of size 5. Display the scores for each participant and also the participant(s) having the highest score.
Example: If the value of N = 4, then the array would be:
Note: Array entries are line fed (i.e. one entry per line)
Test your program with the sample data and some random data:

Example 1
INPUT : N = 5
Participant 1 D A B C C
Participant 2 A A D C B
Participant 3 B A C D B
Participant 4 D A D C B
Participant 5 B C A D D
Key: B C D A A
OUTPUT : Scores :
Participant 1 D A B C C
Participant 1 = 0
Participant 2 = 1
Participant 3 = 1
Participant 4 = 1
Participant 5 = 2
Highest score: Participant 5
Example 2
INPUT : N = 4
Participant 1 A C C B D
Participant 2 B C A A C
Participant 3 B C B A A
Participant 4 C C D D B
Key: A C D B B
OUTPUT : Scores :
Participant 1 = 3
Participant 2 = 1
Participant 3 = 1
Participant 4 = 3
Highest score:
Participant 1
Participant 4
Example 3
INPUT : N = 12
OUTPUT : INPUT SIZE OUT OF RANGE.

Box Packing ISC17

Question : A company manufactures packing cartons in four sizes, i.e. cartons to accommodate 6 boxes, 12 boxes, 24 boxes and 48 boxes. Design a program to accept the number of boxes to be packed (N) by the user (maximum up to 1000 boxes) and display the break-up of the cartons used in descending order of capacity (i.e. preference should be given to the highest capacity available, and if boxes left are less than 6, an extra carton of capacity 6 should be used.)
Test your program with the sample data and some random data:
Example 1
INPUT : N = 726
OUTPUT :
48 x 15 = 720
6 x 1 = 6
Remaining boxes = 0
Total number of boxes = 726
Total number of cartons = 16
Example 2
INPUT : N = 140
OUTPUT :
48 X 2 = 96
24 x 1 = 24
12 x 1 = 12
6 x 1 = 6
Remaining boxes 2 x 1 = 2
Total number of boxes = 140
Total number of cartons = 6
Example 3
INPUT : N = 4296
OUTPUT : INVALID LENGTH

Monday, 30 January 2017

Program to check Upper Triangular matrix

What is Upper Triangular Matrix?  An upper triangular matrix is a square matrix in which all theelements below the diagonal are zero. We consider a Matrix U with ‘i’ rows and ‘j’ columns, thenmathematically we represent the upper triangular matrix as

                                                             upper-triangular-matrix-formula.gif (130×42)
In another word strictly upper triangular matrix is an upper triangular matrix having 0’s along the diagonal as well, i.e., U(ij)=0 for i>=j.
                                                             UpperTriangularMatrix.gif (147×76)

spiral matrix






Outer spiral matrix– arrows are from boundary to core element. Inner Spiral matrix– Arrows are from core elements to boundary elements.

Program for Matrix Multiplication in JAVA...

Matrix Multiplication: Here is given a Java Program for Matrix Multiplication also call matrix product. In other words, Let the two matrix to be multiplied be A and B. Let A is an n × m order matrix and B is an m × p order matrix, their matrix product A*B is an n × p order matrix, in which the m entries across the rows of A are multiplied with the m entries down the columns of B.

Steps for Matrix Multiplication in Java:

Step 1: Make sure that the the number of columns in the 1st matrix equals the number of rows in the 2nd matrix.
Step 2: Multiply the elements of each row of the first matrix by the elements of each column in the second matrix.
Step 3: Add the products.




Iteration 1
Multiplication of matrix A’s first row with each element of matrix B’s all columns,
1*1+2*5, 1*2+2*6, 1*3+2*7, 1*4+2*8
Iteration 2
Multiplication of matrix A’s second row with each element of matrix B’s all columns,
3*1+4*5, 3*2+4*6, 3*3+4*7, 3*4+4*8
Iteration 3
Multiplication of matrix A’s third row with each element of matrix B’s all columns,
5*1+6*5, 5*2+6*6, 5*3+6*7, 5*4+6*8
Iteration 4
Add all the multiplication and get the matrix with an order 3*4.

Mobius Function of number...

The MOBIUS function µ(n) for a natural number N is defined as follows:
µ(n) = 1 if n is a square free positive integer with an even number of prime factors.
µ(n) = 0 if n has a squared prime factor.
µ(n) = -1 if n is a square free positive integer with an odd number of prime factors.
Example:
µ(26)=1                ( for 26 = 2 * 13     µ(26) = ( -1)^2= 1 )
µ(19)=-1               ( for 19 = 19     µ(19) = ( -1)^1= -1 )
µ(62)=1                ( for 62 = 2 * 31     µ(61) = ( -1)^2= 1 )
µ(28)=0                ( for 28 = 2 * 2 * 7     µ(28) = 0 for 2 appears two times )

Thursday, 19 January 2017

Days Elapsed...

Write a program to input two valid dates, each comprising of day          (2 digits), Month (2 digits) and year (4 digits) and calculate the days elapsed between the two dates. Test your program for the following data values:
i) FIRST DATE :              DAY : 24
                                      MONTH: 09
                                      YEAR: 1960
   SECOND DATE :           DAY : 08
                                      MONTH: 12
                                      YEAR: 1852
       
ii) FIRST DATE :             DAY : 10
                                      MONTH: 01
                                      YEAR: 1852
   SECONDDATE :             DAY : 16
                                       MONTH: 10

                                       YEAR: 1952                

Graph...

A sentence is terminated by either “ . ” , “ ! ” or “ ? ” followed by a space. Input a piece of text consisting of sentences. Assume that there will be a maximum of 10 sentences in a block.
Write a program to:
(i)Obtain the length of the sentence (measured in words) and the frequency of vowels in each sentence.
(ii)Generate the output as shown below using the given data
INPUT                   HELLO! HOW ARE YOU? HOPE EVERYTHING IS FINE. BEST OF LUCK.
OUTPUT      Sentence No. of Vowels No. of words
Sentence                No. of vowels          No. of words
1                           2                           1
2                           5                           3
3                           8                            4
4                           3                            3
Sentence                                   No. of words/vowels
1                                              VVVVVV
1                                              WWW
2                                              VVVVVVVVVVVVVVV
2                                              WWWWWWWWWWWW
3                                              VVVVVVVVVVVVVVVVVVVVVVVV
3                                              WWWWWWWWWWWWWWW
4                                              VVVVVVVVV
4                                              WWWWWWWWWWWW

                   Scale used 1:3

Matrix...

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:

a)   Display the input matrix
b)   Find the maximum and minimum value in the matrix and display them along with their position.
c)    Sort the elements of the matrix in ascending order using any standard sorting technique and rearrange them in the matrix.
d)   Output the rearranged matrix.

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
Input:                    M=3            N=22

Output:        Size out of range

Reverse...

The input here will consists of a number of lines of English text consisting of the letters of the English alphabet, the punctuation marks (‘) apostrophe, (.) full stop, (,) comma, (;) semicolon, (:) colon and white space characters (blank, new line). Your task is to print the words of the text in reverse order without a punctuation mark other than blanks. For example consider the following input text:
‘This is a sample piece of text to illustrate this problem. If you are smart you will solve this right’.
 The corresponding output would read as:
‘right this solve will you smart are you If problem this illustrate to text of piece sample a is This’.
That is, the lines are printed in reverse order. Note: Individual words are not reversed.
Input format
The first line of input contains a single integer N( < = 20), indicating the number of lines in the input. This is followed by N lines of input text. Each line should accept a maximum of 80 characters.
Output format
Output the text containing the input lines in reverse order without punctuations except blanks as illustrated above.
Test your program for the following data and some random data.
Input:                    Emotions, controlled and directed to work, is character. By Swami Vivekananda.
Output:                  Vivekananda Swami By character is work to directed and controlled Emotions.

Input :                   Do not judge a book by its cover.
Output:                  cover its by book a judge not Do.

Wondrous Square..

A wondrous square is an n by n grid which fulfils the following conditions:
    (i) It contains integers from 1 to n2, where each integer appears only once.
    (ii) The sum of integers in any row or column must add up to 0.5 * n * (n2 + 1).
For example the following grid is a wondrous square where the sum of each row or column is 65 when n = 5 :
                   17      24      2        8        15
 23      5        7       14      16
 4       6       13       20      22
                   10       12      19      21      3
 11      18      25      2        9
Write a program to read n (2 < = n < = 10) and the values stored in these n by n cells and output if the grid represents a wondrous square or not.
Also output all the prime numbers in the grid along with their row index and column index as shown in the output. A natural number is said to be prime if it has exactly two divisors. E.g. 2, 3, 5, 7, 11,.......
The first element of the given grid i.e. 17 is stored at row index 0 and column index 0 and the next element in the row i.e. 24 is stored at row index 0 and column index 1.
Test your program for the following data and some random data.
SAMPLE DATA:
      INPUT :                     N = 4
16       15      1        2
 6        4       10      14
                        9         8        12      5
                        3         7       11      13
OUTPUT:               YES IT REPRESENTS A WONDROUS SQUARE.



 PRIME                    ROW INDEX                              COLUMN INDEX
 2                                    0                                     3
 3                                    3                                    0
 5                                    2                                    3
 7                                    3                                    1
11                                   3                                    2
13                                   3                                    3
Input           N=4
                   1        2        4
                   3        7       5
                   8        9        6
Output                   not a wondrous square
PRIME                     ROW INDEX                              COLUMN INDEX
 2                                    0                                     0

 2                                    1                                     1

Kaprekar Number...

A positive whole number 'n' that has 'd' number of digits is squared and split into 2 pieces, a right hand piece that has 'd' digits and a left hand piece that has remaining 'd' or 'd-1' digits. If sum of the pieces is equal to the number then it’s a kaprekar number. The first few Kaprekar numbers are: 9, 45, 297…..

For example 297 is a kaprekar number because:
2972 =88209, right hand piece of 88209=209 and left hand piece of 88209=88
Sum=209+88=297 , i.e. equal to the number.

Given the two positive integers p and q, where p < q. Write a program to determine how many kaprekar numbers are there in the range between 'p' and 'q'(both inclusive )and output them.

The input contains two positive integers p and q. Assume p<5000 and q<5000. You are to output the number of kaprekar numbers in the specified range along with their values in the format specified below:
SAMPLE DATA:
INPUT:                  p=1
Q=1000
OUTPUT:     THE KAPREKAR NUMBERS ARE:
1, 9, 45, 55, 99, 297, 999

FREQUENCY OF KAPREKAR NUMBERS IS:8

Bank...

A bank intends to design a program to display the denomination of an
input amount, upto 5 digits. The available denomination with the bank are
of rupees 1000, 500, 100, 50, 20, 10, 5, 2 and 1.

Design a program to accept the amount from the user and display the
break-up in descending order of denominations. (i,e preference should
be given to the highest denomination available) along with the total
number of notes. [Note: only the denomination used should be displayed].
Also print the amount in words according to the digits.

INPUT:                            14836
OUTPUT:               ONE FOUR EIGHT THREE SIX
DENOMINATION:
1000   X       14     =       14000
500    X      1       =       500
100    X      3       =       300
50      X       1       =       50
5        X       1       =       5
1        X       1       =       1

Total                                                  =       14856

Total number of notes                                    =       21

Time to Words...

Given a time in numbers we can convert it into words. For example :
5 : 00                      five o’clock
5 : 10            ten minutes past five
5 : 15                     quarter past five
5 : 30                     half past five
5 : 40           twenty minutes to six
5 : 45                     quarter to six
5 : 47                    thirteen minutes to six
Write a program which first inputs two integers, the first between 1 and 12 (both inclusive) and second between 0 and 59 (both inclusive) and then prints out the time they represent, in words.Your program should follow the format of the examples below.

SAMPLE DATA :
 INPUT :                TIME :         3,0
OUTPUT :              3 : 00 Three o’ clock
INPUT :                 TIME :         7,29
OUTPUT :              7 : 29 Twenty nine minutes past seven
INPUT :                 TIME :         6,34
OUTPUT :              6 : 34 Twenty six minutes to seven
INPUT :                 TIME :         12,1
OUTPUT :              12 : 01 One minute past Twelve
 INPUT :                TIME : 12,45
OUTPUT :              12 : 45 Quarter to One
INPUT :                 TIME : 10,59
OUTPUT :              10 : 59 One minute to Eleven
INPUT :                 TIME : 14,60
OUTPUT :              Incorrect Input

Test your program for the data values given in the examples above and some random data.

Number to words...

Write a program to input a natural number less than 1000 and display it in words. Test your program for the given sample data and some random data.
Input:          29
Output:                  TWENTY NINE
Input:          17
Output:        SEVENTEEN
Input:                    119
Output:                  ONE HUNDRED AND NINETEEN
Input:          220

Output:        TWO HUNDRED AND TWENTY


Prime Palindromic...

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:
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


INPUT:                  M=100
N=5000
OUTPUT:               Out of Range

Encryption

Encryption is the technique of coding message to maintain their secrecy. A string of size ‘n’ where n is greator than 1 and less than 10, stores single sentences (each sentence ends with a full Stop ) in each row of the array.
Write a program to accept the size of the array. Display an appropriate message if the size is not satisfying the given condition. Define a string array of the input size and fill it with sentence row-wise.
Change the sentence of the odd rows with an encryption of tho characters ahead of  the original characters. Also change the sentence of the even rows by sorting the sentence in reverse order/
Display the encrypt sentences as per the sample data given below:

Test your program with some sample data and some random data.

Input:          N=4
                             IT IS CLOUDY.
                             IT MAY RAIN.
                             THE WEATHER IS FINE.
                             IT IS COOL.
OUTPUT:
                             KV KU ENQWFA.
                             RAIN MAY IT.
                             VJG YGCV JGT KU HKPG.
                             COOL IS IT.


Merge Sort...

Write a program that inputs the names of people in to different arrays, A and B. Array A has N number of names while array B has M number of names, with no duplicates in either of them. Merge arrays A and B in to a single array C, such that the resulting array is stored alphabetically.
Display all the three arrays, A, B and C, stored alphabetically.
Test your program for the given data and some random data.

SAMPLE DATA
INPUT
Enter number of names in Array A, N = 2
Enter number of names in Array A, B = 2
First array:           (A)
Suman
Anil

Second array:                  (B)
Usha
Sachin
John

OUTPUT
Stored Merged array:       (C)
Anil
John
Sachin
Suman
Usha

Stored First array:           (A)
Anil
Suman

Stored second array:        (B)
John
Sachin

Usha

Smith Number...

A Smith number is a composite number, the sum of whose digits is the sum of the digits of its prime factors obtained as a result of prime factorization (excluding 1). The first few such numbers are 4, 22, 27, 58, 85, 94, 121 …..

Example :
1.    666
Prime factors are 2, 3, 3, and 37
Sum of the digits are (6+6+6)=18
Sum of digits of the factors (2+3+3+(3+7))=18

2.   4937775
Prime factors are 3, 5, 5, 65837
Sum of the digits are (4+9+3+7+7+7+5)=42
Sum of digits of the factors (3+5+5+(6+5+8+3+7))=42

Write a program to input a number and display whether the number is Smith number or not.
Sample data:
          Input 94               output                   Smith Number
          Input 102              output                   NOT Smith Number
          Input 666             output                   Smith Number

          Input 999              output                   NOT Smith Number

Goldbach Number ISC 2018

Question: A Goldbach number is a positive even integer that can be expressed as the sum of two odd primes. Note: All even integer numbers ...