Practical_Programming_NumericArraysStringMay2024 (1)
Practical_Programming_NumericArraysStringMay2024 (1)
1. Copy your completed Java Assignment programs: (typed, compiled, executed programs with
no errors) + output to word document and save filename as: yournameAssignPractical
Prog.docx
2. Document Format that to be followed : Set:-
a) Page Size : A4
b) Default Left margin: ( No change)
c) Type you name : Header : Top Right corner
d) Insert Page Number : Footer : Bottom Right corner
e) Font size : 12
f) Font name : Times New Roman
g) Paragraph spacing : 1.15
h) Apply PageBorder : Box – Single line
3. Save file and submit the document in your managebac account by due date
4. Final print submission for Board Practical : should contain the following
a. Assignment Question Paper: provided should be attached to the final print.
b. Program Listing: Copy the Java compiled program to word document with remarks and
meaningful variable names.
c. Output of the program: Maximum 3 to 4 outputs covering all range of inputs.
-----------------------------------------------
1. String Based.
A new advanced Operating System, incorporating the latest hi-tech features has been designed by Opera
Computer Systems. The task of generating copy protection codes to prevent software piracy has been entrusted
to the Security Department. The Security Department has decided to have codes containing a jumbled
combination of alternate uppercase letters of the alphabet starting from A upto K (namely among A, C, E, G,
I, K). The code or may not be in the consecutive series of alphabets. Each code should not exceed 6 characters
and there should be no repetition of characters. If it exceeds 6 characters, display an appropriate error message.
Write a program to input a code and its length. At the first instance of an error display “Invalid!” stating an
appropriate reason. In case of no error, display the message “Valid!”. Test your program for the following data
and some random data.
SAMPLE DATA
INPUT N=4
ABCE
OUPUT Invalid! Only alternate letters permitted!
INPUT N=4
AcIK
OUPUT Invalid! Only upper case letters permitted!
INPUT N=4
AAKE
OUPUT Invalid! Repetition of characters not permitted!
INPUT N=7
ABCE
OUPUT Error! Length of string should not exceed 6 characters!
INPUT N=4
AEGIK
OUPUT Invalid! String length not the same as specified!
INPUT N=3
ACE
OUPUT Valid!
INPUT N=5
GEAIK
OUPUT Valid!
2. The potential of a word is found by adding the ASCII value of the alphabets.
(ASCII values of A to Z are 65 to 90).
Example: BALL Potential = 66 + 65 + 76 + 76 = 283
Write a program to accept a sentence which may be terminated by either “ . ” , “ ? ” or “ ! ” only. The words of
sentence are separated by single blank space and are in UPPER CASE. Decode the words according to their potential
and arrange them in ascending order of their potential strength.
Test your program with the following data and some random data:
Example 1:
INPUT: HOW DO YOU DO?
Example 2:
Example 3:
INPUT: HOW ARE YOU#
OUTPUT: INVALID INPUT
3. Write a program to accept a sentence which may be terminated by either ‘.’, ‘?’ or ‘!’ only. Any other character may
be ignored. The words may be separated by more than one blank space and are in UPPER CASE.
Perform the following tasks:
a) Accept a sentence and reduce all the extra blank space between 2 words to a single blank space.
b) Accept a word from the user which is part of the sentence along with its position number
and delete the word and display the sentence.
Test your program for the following data and some random data:
Example 1
INPUT: A MORNING WALK IS A IS BLESSING FOR THE WHOLE DAY.
WORD TO BE DELETED: IS
WORD POSITION IN THE SENTENCE :6
OUTPUT: A MORNING WALK IS A BLESSING FOR THE WHOLE DAY
Example 2
Example 3
Numerical Based.
Question 1.
An ISBN (International Standard Book Number) is a ten-digit code which uniquely identifies a book.
The first nine digits represent the group, publisher and title of the book and the last digit is used to check
whether ISBN is correct or not.
Each of the first nine digits of the code can take a value between 0 to 9. Sometimes it is necessary to make the
last digit equal to ten. This is done by writing the last digit of the code as X.
To verify an ISBN, calculate 10 times the first digit, plus 9 times the second digit, plus 8 times the third digit
and so on until we add 1 time the last digit. If the final number leaves no remainder while divided by 11, the
code is a valid ISBN
For example:
0201103311=10*0+9*2+8*0+7*1+6*1+5*0+4*3+3*3+2*1+1*1=55
007462542X=10*0+9*0+8*7+7*4+6*6+5*2+4*5+3*4+2*2+1*10=176
Test Data:
Input code: 0201530821
Output: Sum=99
Leaves no remainder – valid ISBN
Input code: 356680324
Output: Sum=invalid input
Input code: 0231428031
Output: Sum=122
Leaves remainder – invalid ISBN
Question 2.
Write a Java program to check whether a given number is a happy number or unhappy number.
Happy number: Starting with any positive integer, replace the number by the sum of the squares of its
digits, and repeat the process until the number equals 1, or it loops endlessly in a cycle which does not
include 1.
An unhappy number is a number that is not happy.
The first few unhappy numbers are 2, 3, 4, 5, 6, 8, 9, 11, 12, 14, 15, 16, 17, 18, 20.
Question 3. 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 the 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 the 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 a 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
Arrays.
Question 1.
Write a program to input a natural number less than 1000 and display it in words using the concept of
Arrays.
Test your program for the given sample data and some random data.
Sample Data:
Input: 29
Output: TWENTY NINE
Input: 17001
Output: OUT OF RANGE
Input: 119
Output: ONE HUNDRED AND NINETEEN
Input:500
Output: FIVE HUNDRED
Question 2.
There are 2 set of SAT sessions SAT1 and SAT2 happening in a school, where only the first name of the
students is enrolled in two different arrays. Both arrays have M and N number of names in the arrays with
no duplicates in either of them, the second student with same name while entering are given a cue card
number as R1 attached to their end of the name, second same duplicate with R2 and so on. Merge the arrays
SAT1 and SAT2 into a single array SAT such that the resulting array is sorted alphabetically using Bubble
sort technique. Finally display all the three arrays.
Test your program for the following data and some random data:
Input : Enter the names in array SAT1 :N= 2
Enter the names in array SAT2 :N= 4
SAT1 group : Anil
Zaheer
SAT2 group : Keerti
Udit
John
JohnR1
Final Output: SAT1 group should be printed in sorted order
SAT2 group should be printed in sorted order
SAT group :
Anil
John
JohnR1
Keerti
Udit
Zaheer
Question 3.
Write a program in Java to store the numbers in NxN DDA. Display the input number in matrix format. Find
and display highest and lowest number among the stored number in the DDA along with its position. Any
duplicate numbers also should be displayed with its position.
81 80 66 10
58 65 80 12
55 33 12 14