Computer Project Manthan
Computer Project Manthan
SCHOOL
248001- Dehradun, Uttarakhand
PROJECT OF
COMPUTER SCIENCE
(2024-25)
1
ACKNOWLEDGEMENT
I would like to extend my sincere thanks to Mrs. Khila Bhandari my Computer teacher, for
her valuable guidance and support throughout the duration of this project. Her insights and
feedback have been immensely helpful and have greatly contributed to the completion of this
work.
Special thanks go to my family, who have provided me with the necessary resources and a
conducive environment to work on this project. Their constant encouragement and belief in
my abilities have been a source of motivation.
Lastly, I thank all those who directly or indirectly contributed to the success of this project .
~Manthan Dhiman
INDEX
2
S.NO TITLE PAGE REMARK
1. Program to calculate the sum of two matrices 4
2. Program to find the transpose of the given matrix 7
3. Program to check if the matrix is symmetric or not 10
4. Program to search a number in the given matrix 13
5. Program to calculate the product of given matrices 16
6. Program to find given string is palindrome or not 19
7. Program to count the number of words in the given
string 21
PROGRAMS
3
Ques 1. Write a program to calculate the sum of two given matrices: -
Algorithm: -
1. Start
2. Declare class
3. Declare scanner class
4. Taking the size of matrix as input to variable ‘l’ & ’w’
5. Declaring variables for loop i.e. ‘i’ & ‘j’
6. Declaring 2D array ‘a’ & ’b’
7. Taking matrix 1 elements as input and displaying them
8. Taking matrix 2 elements as input and displaying them
9. Calculating the sum in a matrix ‘sum’
10. Displaying the sum
11. Stop
4
{
for(j=0;j<w;j++)
{
a[i][j]=sc.nextInt();
}
}
System.out.println("Matrix 1 elements:");
for(i=0;i<l;i++){
for(j=0;j<w;j++){
System.out.print(a[i][j]+" \t ");
}
System.out.println();
}
System.out.println("Enter matrix 2 elements:");
for(i=0;i<l;i++){
for(j=0;j<w;j++){
b[i][j]=sc.nextInt();
}
}
System.out.println("Matrix 2 elements:");
for(i=0;i<l;i++){
for(j=0;j<w;j++){
System.out.print(b[i][j]+" \t ");
}
System.out.println();
}
System.out.println("SUM of matrix:");
for(i=0;i<l;i++){
for(j=0;j<w;j++){
sum[i][j]=a[i][j]+b[i][j];
}
5
}
for(i=0;i<l;i++){
for(j=0;j<w;j++){
System.out.print(sum[i][j]+" ");
}
System.out.println();
}
}
}
Output:-
6
Algorithm:-
1. Start
2. Declare class
3. Declare Scanner class
4. Taking the size of matrix as input to variable ‘l’ & ‘b’
5. Declaring matrix ‘a’
6. Declaring Transpose matrix ‘T’
7. Taking matrix elements as input and displaying them
8. Calculating the transpose and storing it in matrix ‘T’
9. Displaying the transpose matrix
10. Stop
for(int i=0;i<l;i++){
for(int j=0;j<b;j++){
7
System.out.print(a[i][j]+"\t");
}
System.out.println();
}
for(int i=0;i<l;i++){
for(int j=0;j<b;j++){
T[j][i]=a[i][j];
}
}
System.out.println("Transpose:");
for(int i=0;i<l;i++){
for(int j=0;j<b;j++){
System.out.print(T[i][j]+"\t");
}
System.out.println();
}
}
}
Output:-
8
Ques 3. Write a program to check the given matrix is symmetric or not:-
9
Algorithm:-
1. Start
2. Declare class
3. Declare scanner class
4. Taking the size of matrix as input to variable ‘l’ & ’b’
5. Declaring 2D array ‘a’ & ’b’
6. Taking matrix elements as input and displaying them
7. Checking if the matrix is a square matrix or not
8. If matrix is not square then it is not symmetric
9. If matrix is square then check the elements
10. Display the result accordingly
11. Stop
Output:-
11
12
Ques 4. Write a program to find a number in the given matrix:-
Algorithm:-
1. Start
2. Declare class
3. Declare scanner class
4. Taking the size of matrix as input to variable ‘l’ & ’b’
5. Declaring a matrix ‘a’
6. Taking matrix elements as input and displaying them
7. Checking if the matrix is a square matrix or not
8. Displaying the transpose matrix
9. Stop
13
System.out.println("Matrix elements:");
for(int i=0;i<l;i++){
for(int j=0;j<b;j++){
System.out.print(a[i][j]+"\t");
}
System.out.println();
}
for(int i=0;i<l;i++){
for(int j=0;j<b;j++){
if(a[i][j]==n){
k=1;
}
}
}
System.out.println("******************************");
if(k==1){
System.out.println("Number Found");
}
else{
System.out.println("Number not found");
}
System.out.println("******************************");
}
}
14
Output: -
15
Ques 5. Write a program to calculate the product of two matrices given by the user:-
Algorithm:-
1. Start
2. Declare class
3. Declare scanner class
4. Taking the size of matrix as input to variable ‘l’
5. Declaring a matrix ‘a’ & ‘b’
6. Taking matrix elements as input and displaying them
7. Calculating the product of matrices
8. Displaying the result
9. Stop
16
for(i=0;i<l;i++){
for(j=0;j<l;j++){
System.out.print(a[i][j]+" ");
}
System.out.println();
}
System.out.println("Enter "+l+"X"+l+" matrix 2 elements:");
for(i=0;i<l;i++){
for(j=0;j<l;j++){
b[i][j]=sc.nextInt();
}
}
System.out.println("Matrix 2 elements:");
for(i=0;i<l;i++){
for(j=0;j<l;j++){
System.out.print(b[i][j]+" ");
}
System.out.println();
}
System.out.println("Multiplication of matrix:");
for(i=0;i<l;i++){
for(j=0;j<l;j++){
product[i][j]=0;
for(int k=0;k<l;k++){
product[i][j]+=a[i][k]*b[k][j];
}//end of k loop
System.out.print(product[i][j]+" "); //printing matrix element
}//end of j loop
System.out.println();//new line
}
}
17
}
Output:-
18
Ques 6. Write a program to find the entered string is palindrome or not:-
Algorithm:-
1. Start
2. Declare class
3. Declare scanner class
4. Declare string variables to store string and its reverse
5. Taking the original string as input and storing it in ‘str’ then displaying it
6. Finding the reverse of the string and storing it in ‘revstr’
7. Checking if the string is palindrome or not
8. Displaying the result accordingly
9. Stop
19
else{
Output:-
20
Ques 7. Write a program to count the number of words in the given string:-
Algorithm:-
1. Start
2. Declare class
3. Declare scanner class
4. Declare string variables to store string
5. Taking sting as Input
6. Logic to count the words in the sentence
7. Displaying the result accordingly
8. Stop
Output:-
22
Ques 8. Write a program to count the repetition of an alphabet in a string:-
Algorithm:-
1. Start
2. Declare class
3. Declare scanner class
4. Declare string variables to store string
5. Taking sting as Input
6. Take the alphabet to count as input
7. Count the number of times alphabet is repeating
8. Displaying the result accordingly
9. Stop
23
}
}
System.out.println("Number of times "+a+" is present: "+k);
}
}
Output:-
24
Ques 9. Write a program to separate words with even length from a given string:-
Algorithm:-
1. Start
2. Declare class
3. Declare scanner class
4. Declare string variables to store string
5. Taking sting as Input
6. Converting string into a string type array
7. Checking if the word has even length or not
8. Displaying the words with even length
9. Stop
//program to print the words with even length from the given string
import java.util.*;
class EvenLength
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
String s;
int l;
System.out.println("Enter the String:");
s=sc.nextLine();
l=s.length();
System.out.println("Words with even length:");
String str[]=s.split(" ");
for(int i=0;i<str.length;i++){
if(str[i].length()%2==0){
System.out.println(str[i]);
}
}
}
}
25
Output:-
26
Ques 10. Write a program to count the total number of uppercase, lowercase, special
characters and digits in a given string:-
Algorithm:-
1. Start
2. Declare class
3. Declare scanner class
4. Declare string variables to store string
5. Taking sting as Input
6. Count the number of all types of characters and store their values
7. Display the result
8. Stop
// program to count the total number of uppercase, lowercase, special characters and digits in
a given string
import java.util.*;
class Count
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
String s;
int u,l,sp,d,i;
u=l=sp=d=0;
char c;
System.out.println("Enter the string:");
s=sc.nextLine();
for(i=0;i<s.length();i++){
c=s.charAt(i);
if(Character.isUpperCase(c)){
u++;
}
else if(Character.isLowerCase(c)){
l++;
27
}
else if(Character.isDigit(c)){
d++;
}
else{
sp++;
}
}
System.out.println("**************************");
System.out.println("UPPERCASE: "+"\t"+u);
System.out.println("LOWERCASE: "+"\t"+l);
System.out.println("DIGITS: "+"\t"+d);
System.out.println("SPECIAL CHARACTER: "+"\t"+sp);
}
}
Output:-
28
Ques 11. Write a program to print all the palindrome words in the given sentence:-
Algorithm:-
1. Start
2. Declare class
3. Declare scanner class
4. Declare string variables to store string
5. Taking sting as Input
6. Converting sentence to array of string
7. Logic to find which word is palindrome
8. Printing the words which are palindrome
9. Stop
Output:-
30
Ques 12. Write a program to check entered number is prime or not:-
Algorithm:-
1. Start
2. Declare class
3. Declare scanner class
4. Taking the number as input
5. Checking if the number is prime or not
6. Displaying the result
7. Stop
if (k==1) {
System.out.println(num + " is a prime number.");
} else {
31
System.out.println(num + " is not a prime number.");
}
}
}
Output:-
32
Ques 13. Write a program to check the entered number is neon or not:-
(A neon number is a number where the sum of digits of square of the number is equal to the number.)
Algorithm:-
1. Start
2. Declare class
3. Declare scanner class
4. Taking the number as input
5. Checking if the number is neon or not
6. Displaying the result accordingly
7. Stop
33
}
Output:-
34
Ques 14. Write a program to convert the entered Decimal number to its binary
equivalent:-
Algorithm:-
1. Start
2. Declare class
3. Declare scanner class
4. Taking the number as input
5. Converting the number to its binary equivalent
6. Displaying the result
7. Stop
35
Output:-
36
Ques 15. Write a program to calculate the factorial of a given number:-
Algorithm:-
1. Start
2. Declare class
3. Declare scanner class
4. Taking the number as input
5. Calculating the factorial
6. Displaying the result
7. Stop
37
Output:-
38
Bibliography
~Thank You
39