0% found this document useful (0 votes)
16 views

Project 2023

The document outlines 12 programming problems involving arrays and loops in Java. The problems cover topics like Armstrong numbers, series calculations, pattern printing, array sorting/searching, matrix operations, and boundary/non-boundary element sums. For each problem, the document provides the class name, data members, constructor, and key methods to implement the required logic.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

Project 2023

The document outlines 12 programming problems involving arrays and loops in Java. The problems cover topics like Armstrong numbers, series calculations, pattern printing, array sorting/searching, matrix operations, and boundary/non-boundary element sums. For each problem, the document provides the class name, data members, constructor, and key methods to implement the required logic.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Class : XI

Subject : Computer Science (Practical File programs),Year 2023-24

1. Write a program in Java to display all 3-digits Armstrong numbers .


Instance methods are:-
public boolean isArmstrong(int num)- This method will check whether parameter num is an Armstrong Number
or not and returns true or false accordingly.
public void findAndDisplay() – this method will display all 3-digit Armstrong Numbers with the help of
isArmstrong() method.
Write main() to create object of the class and to call the above methods accordingly.
2. Write a program in Java to display the sum of the following series-
Class name:- SumOfseries
Sum= 1/2!+2/4!+3/6!+....n terms
Instance variables/Data Members are-
int n- stores number of terms(n>0).
double sum – stores the sum of the series
Instance methods are-
public void input( ) – This method accepts total number of terms.Display “Invalid Input” if n <=0
public void calculate()- This method calculates the sum of the series with the help of getFactorial().
public void display( )- This method displays the sum.
public double getFactorial(int num)- This method calculates and returns the factorial of num.
Write main( ) to create object of the Class SumOfSeries and call the above methods accordingly.
3. Write a program in Java to input lower and upper limit and display all the special numbers within the limit . A
special number is a number whose sum of the odd digits is equal to the sum of the even digits. Display error
message if lower limit is not less than upper limit.
Class name:- SpecialNumbersInARange
Data Members are-
int lower- stores the lower limit
int upper-stores the upper limit
Instance methods are-
public void input( ) – This method accepts lower and upper limit value.
public void display( )- This method displays all the special numbers between lower and upper limits with the help
of isSpecial( ).
public boolean isSpecial(int num)- This method checks whether num is a Special number or not and returns true
or false accordingly.
Write main( ) to create object of the Class SpecialNumbersInARange and call the above methods accordingly.

4. Write a menu driven program using Object –Oriented Concept to print the following patterns :-
Class Name: Patterns
Instance methods are-
public void display1( ) – displays the following pattern for 5 rows.
1
10
101
1010
10101
public void display2( ) – displays the following pattern for 5 rows.
ABCDE
ABCD1
ABC12
AB123
A1234

public void display3( ) -displays the following pattern for 5 rows-

123
12345
1234567
123456789
Write main() to create object and to display the above methods.
5. Write a menu driven program to print the patterns :
Class Name: FewMorePatterns
Instance Methods are as follows:-
i) 1
121
12321
1234321
123454321
public void display1( int n) – displays the above pattern for n rows.
ii) 54321
4321
321
21
1
public void display2( int n) – displays the above pattern for n rows.
iii) 13579
35791
57913
79135
91357

public void display3( ) - displays the above pattern for 5 rows.

Write main( ) to create object of the Class FewMorePatterns and call the above methods accordingly.

6. Design a Java class to input n integers in an 1-D array, read the array and display the sum of digits of each 3-digit
number present in the array.
Class Name : ArraySumOfDigits
Instance variables are:
int[] arr – refers to the array object
int size- refers to the array size
Instance Methods are as follows:-
public ArraySumOfDigits (int n )- parameterized constructor to initialize size=n and allocate space for the array
object.
public void input( ) – accepts array elements and stores in the array.
public void getSumOfDigit( ) – reads the array, checks if an array value is a 3-digit number or not and calculates
the sum of digits if the value is a 3-digit number. Displays the sum .
public void display( ) – displays the array values.
Write main( ) to create object of the class ArraySumOfDigits and call the above methods accordingly.
7. Design a Java class to input n integers in an 1-D array, reverse the array and display the reversed array.
Class Name : ArrayReverse
Instance variables are:
int[] arr – refers to the array object
int size- refers to the array size
Instance Methods are as follows:-
public ArrayReverse(int n )- parameterized constructor to initialize size=n and allocate space for the array object.
public void input( ) – accepts array elements and stores in the array.
public void reverse( ) – reverses the array by swapping 1st and last values ,2nd and 2nd last values and so on.
public void display( ) – displays the array values.
Write main( ) to create object of the class ArrayReverse and call the above methods accordingly.
8. Design a Java class to input n integers in an 1-D array, arranges the array in descending order using selection sort
and display the arranged array.
Class Name : Arrange
Instance variables are:
int[ ] arr – refers to the array object
int size- refers to the array size
Instance Methods are as follows:-
public Arrange(int n )- parameterized constructor to initialize size=n and allocate space for the array object.
public void input( ) – accepts array elements and stores in the array.
public void sort( ) – this method will arrange the array in descending order using selection sort algorithm
public void display( ) – displays the array values.
Write main( ) to create object of the class Arrange and call the above methods accordingly.
9. Design a Java class to input n integers in an 1-D array, arranges the array in ascending order using bubble sort and
then input a number to search in the array using binary search algorithm.
Class Name : BinarySearch
Instance variables are:
int[ ] arr – refers to the array object
int size- refers to the array size
int num – refers to the number to be searched using binary search.
Instance Methods are as follows:-
public BinarySearch (int n )- parameterized constructor to initialize size=n and allocate space for the array object.
public void input( ) – accepts array elements and stores in the array. The number to be searched also needs to be
entered here.
public void sort( ) – this method will arrange the array in ascending order using bubble sort algorithm.
public boolean search( ) – searches num in the array using binary search and returns true if found otherwise
returns false.
public void display( ) – displays the message “Number is found” or “Number is not found” by calling search( ) .
Write main( ) to create object of the class BinarySearch and call the above methods accordingly.
10. Declare a square matrix of size 4*4, input 16 integers, find the sum of primary and secondary diagonal elements
separately. Then display the sum and the original matrix.
Class name: SumOfDiagonals
Instance variables/data Members:-
int[ ][ ] arr – refers to the array object
int size- refers to the array size(no. of rows=no. of columns here)
Instance Methods are as follows:-
public SumOfDiagonals (int n )- parameterized constructor to initialize size=n and allocate space for the array
object.
public void input( ) – accepts array elements and stores in the array.
public void getSum( ) – this method calculate the sum of primary and secondary diagonal elements separately.
public void display( ) – Displays the 2-D array in matrix format. .
Write main( ) to create object of the class SumOfDiagonals and call the above methods accordingly.
11. Store integers in a 2-D array of size N X M and display the 2-D array in matrix format. Reverse each row of the
matrix and then display the updated matrix.
Class name: ReverseEachRow
int[ ][ ] arr – refers to the array object
int N,M- refers to the array size.
Instance Methods are as follows:-
public ReverseEachRow (int row,int col )- parameterized constructor to initialize N=row ,N=col and allocate space
for the array object.
public void input( ) – accepts array elements and stores in the array.
public void doReverse( ) – this method reverses each row of the matrix
public void display( ) – Displays the 2-D array in matrix format. .
Write main( ) to create object of the class ReverseEachRow and call the above methods accordingly.
Sample input Output :
How many rows ? 4
How many columns ? 3
Input 3 numbers per row :
123
456
789
123
The original Matrix is:-
123
456
789
123
The Output matrix is-
321
654
987
321
12. Input integers in a 2-D array of size N X M where M,N>3 Display the sum of the boundary elements and non -
boundary elements separately.
Class name: BoundaryNonBoundary
int[ ][ ] arr – refers to the array object
int N,M- refers to the array size.
Instance Methods are as follows:-
public void input( ) – accepts array size and allocates array object. Checks for the invalid size ,displays proper
message and terminates the program otherwise enters array elements and stores in the array.
public void doSum( ) – this method will add the boundary values and non-boundary values separately and displays
them with a proper message.
public void display( ) – Displays the 2-D array in matrix format.
Write main( ) to create object of the class BoundaryNonBoundary and call the above methods accordingly.
Sample input Output :
How many rows ? 4
How many columns ? 4
Input 4 numbers per row :
1234
4561
7890
1230
The original Matrix is:-
1234
4561
7790
1230
The sum of the boundary values is=28
The sum of the Non- boundary values is=27
Sample input Output :
How many rows ? 3
How many columns ? 4
Output: Invalid Size
13. Input integers in a 2-D array of size N X M. Display the maximum, minimum, Sum and average values row wise.
Sample Input /Output –
Sample input Output :
How many rows ? 4
How many columns ? 3
Input 3 numbers per row :
123
456
789
123
Row# : 1
Maximum=3 , Minimum=1 , Sum= 6 , Average=2.0
Row# : 2
Maximum=6 , Minimum=4 , Sum= 15, Average=5.0
Row# : 3
Maximum=9 , Minimum=7 , Sum= 24 , Average=8.0
Row# : 4
Maximum=3 , Minimum=1 , Sum= 6 , Average=2.0

14. Input 10 words and then arrange them according to total number of characters present in them.
Sample I/O :
Enter 10 words-
Alphabet
Arrange
Box
Sky
Pencil
Bangles
Mobile
Charger
Knife
Book
Arranged words are-
Box
Sky
Book
Knife
Pencil
Mobile
Arrange
Bangles
Charger
Alphabet
15. Input a sentence. Split the sentence into words. Display each word in reversed format.
Sample Input/Output:
Enter a Sentence : honesty is the best policy
Output is : ytsenoh si eht tseb ycilop
16. Input a line. Display each word with total number of vowel and consonant. Then display the words which have
equal number of vowel and consonant.
Sample Input/ Output:
Enter a sentence : Soul never dies
Word No. Of Vowel No. Of Consonant
Soul 2 2
Never 2 3
Dies 2 2
Words with equal number of vowel and consonant are-
Soul
dies

17. A special word is a word which starts and ends with same letter. Input a sentence and then display only the special
words. Then form another sentence with all the words which do not start and end with the same letter.
Sample Input/Output:
Enter a sentence: Ahana is a nice girl and Indrani likes to play with her.
Outpit:
Special words are-
Ahana
Indrani
Sentence is –
is a nice girl and Indrani likes to play with her.
18. Input a sentence and encrypt each word by converting it to piglatin word. Convert each word to uppercase. If
vowel is present in a word, then extract all the characters before the first vowel and concatenate at the end of
the word and then concatenate “AY”. If a word does not contain vowel then the word will remain same. If a word
starts with a vowel then concatenate “AY” at the end.
Generate a new sentence and display the new sentence.
Sample Input/Output:
Enter a sentence: Ahana is a nice girl .
Output is : AHANAAY ISAY AAY ENICAY IRLGAY.
Enter a sentence: Sky is blue
Output is : SKY ISAY UEBLAY

You might also like