COMPUTER PROJECT (2ndTerm)
NAME - ASTITVA SHAW
CLASS - XI
ROLL No. - 5
Section - A
Session - 2024-25
ACKNOWLEDGEMENT
I would like to take this opportunity to express my gratitude to those who supported
me during the completion of this school project. Firstly, I want to thank my teacher for
their guidance and encouragement. Their insights and feedback were invaluable in
shaping the direction of my work.
I also want to acknowledge the support of my family and friends. Their
encouragement and understanding provided me with the motivation to tackle
challenges and persevere until the project was completed.
Thank you to everyone who played a part in the project.
Astitva Shaw
COMPUTER PROJECT 1
CONTENTS
SL. NO TOPIC PAGE NO.
1 Acknowledgement 1
2 Program 1 3-6
3 Program 2 7-9
4 Program 3 10-12
5 Program 4 13-15
6 Program 5 16-17
7 Program 6 18
8 Program 7 19
9 Program 8 20-21
10 Program 9 22-23
11 Program 10 24-25
12 Conclusion 26
COMPUTER PROJECT 2
PROGRAM - 1
Write a program in JAVA to input two matrices. Display the original
matrices and the matrix after multiplication.
Source Code:
import java.util.Scanner;
public class Q1
{
int [][]num1;
int [][]num2;
public void input()
{
Scanner in = new Scanner(System.in);
System.out.print("Enter number of rows in first matrix: ");
int r = in.nextInt();
System.out.print("Enter number of columns in first matrix: ");
int c = in.nextInt();
num1 = new int[r][c];
System.out.println("Enter the numbers in first matrix:-");
for(int i = 0; i<r; i++)
{
for(int j = 0; j<c; j++)
{
num1[i][j]=in.nextInt();
}
}
System.out.print("Enter number of rows in second matrix: ");
r = in.nextInt();
System.out.print("Enter number of columns in second matrix: ");
c = in.nextInt();
num2 = new int[r][c];
System.out.println("Enter the numbers in second matrix:-");
for(int i = 0; i<r; i++)
{
for(int j = 0; j<c; j++)
{
num2[i][j]=in.nextInt();
}
}
}
public static int[][] Multiply(int[][] m1, int[][] m2)//method to multiply two matrices
{
int [][]p = new int[m1.length][m2[0].length];
COMPUTER PROJECT 3
//rows of product matrix will be equal to rows of m1
//columns of product matrix will be equal to columns of m2
int pro;//variable to temporarily store product of elements of matrix
for(int i = 0; i<m1.length; i++)// variable i is the row number for product matrix
{
for(int j = 0; j<m2[0].length; j++)//variable j is column number for product matrix
{
pro = 0;
for(int k = 0; k<m1[0].length; k++)//loop which will calculate the product for
p[i][j] element
{
pro += m1[i][k]*m2[k][j];
//just take out a notebook to understand this by dry run
}
p[i][j] = pro;//assigning the product value
}
}
return p;
}
public void show()
{
System.out.println("Original first matrix:-");
for(int i = 0; i< num1.length; i++)
{
for(int j = 0; j<num1[0].length; j++)
{
System.out.print(num1[i][j]+"\t");
}
System.out.println();
}
System.out.println("Original second matrix:-");
for(int i = 0; i< num2.length; i++)
{
for(int j = 0; j<num2[0].length; j++)
{
System.out.print(num2[i][j]+"\t");
}
System.out.println();
}
if(num1[0].length == num2.length)
{
int[][] m = Multiply(num1, num2);
System.out.println("Multiplication Matrix:-");
for (int i = 0; i < m.length; i++)
{
COMPUTER PROJECT 4
for (int j = 0; j < m[0].length; j++)
{
System.out.print(m[i][j] + "\t");
}
System.out.println();
}
}
else
System.out.println("Matrix multiplication is not possible");
}
}
VARIABLE DESCRIPTION
NAME TYPE PURPOSE
num1 int[][] To store first matrix
num2 int[][] To store second matrix
in Scanner Scanner object for input
r int To store number of rows
c int To store number of columns
i int Loop Counter
j int Loop Counter
m1 int[][] To store first matrix in
argument
m2 int[][] To store second matrix in
argument
p int[][] To store product matrix
pro int To store product temporarily
OUTPUT:
Enter number of rows in first matrix: 3
Enter number of columns in first matrix: 2
Enter the numbers in first matrix:-
1
2
3
COMPUTER PROJECT 5
4
5
6
Enter number of rows in second matrix: 2
Enter number of columns in second matrix: 3
Enter the numbers in second matrix:-
6
5
4
3
2
1
Original first matrix:-
1 2
3 4
5 6
Original second matrix:-
6 5 4
3 2 1
Multiplication Matrix:-
12 9 6
30 23 16
48 37 26
COMPUTER PROJECT 6
PROGRAM - 2
Write a program in java to input a matrix. Display the original matrix and
the matrix after arranging all elements in ascending order.
Source Code:
import java.util.Scanner;
public class Q2
{
int [][]num;
public void input()
{
Scanner in = new Scanner(System.in);
System.out.print("Enter the number of rows: ");
int r = in.nextInt();//taking input number of rows
System.out.print("Enter the number of columns: ");
int m = in.nextInt();//taking input number of columns
num = new int[r][m];
System.out.println("Enter the elements of matrix:-");
for(int i=0;i<r;i++)//taking input the matrix
{
for(int j=0;j<m;j++)
{
num[i][j]=in.nextInt();
}
}
}
public static void sortMatrix(int[][] matrix)//function to sort matrix
{
int rows = matrix.length;
int cols = matrix[0].length;
int[] flatArray = new int[rows * cols];
int index = 0;
for (int[] row : matrix) {
for (int value : row) {
flatArray[index++] = value;
}
}
for (int i = 0; i < flatArray.length - 1; i++) {
for (int j = 0; j < flatArray.length - 1 - i; j++) {
if (flatArray[j] > flatArray[j + 1]) {
int temp = flatArray[j];
COMPUTER PROJECT 7
flatArray[j] = flatArray[j + 1];
flatArray[j + 1] = temp;
}
}
}
index = 0;
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
matrix[i][j] = flatArray[index++];
}
}
}
public void show()
{
System.out.println("Original Matrix");
for(int i=0;i<num.length;i++)
{
for(int j=0;j<num[i].length;j++)
{
System.out.print(num[i][j]+" ");
}
System.out.println();
}
sortMatrix(num);
System.out.println("Sorted Matrix");
for(int i=0;i<num.length;i++)
{
for(int j=0;j<num[i].length;j++)
{
System.out.print(num[i][j]+" ");
}
}
}
}
VARIABLE DESCRIPTION
NAME TYPE PURPOSE
num int[][] To store matrix
in Scanner Scanner object for input
COMPUTER PROJECT 8
i int Loop Counter
j int Loop Counter
r int To store number of rows
m int To store number of columns
matrix int[][] To accept matrix in
argument
rows int To store number of rows
cols int To store number of columns
flatArray int[] To store all elements of
matrix
value int Buffer for elements of
matrix
index int Loop counter as index
OUTPUT:
Enter the number of rows: 5
Enter the number of columns: 2
Enter the elements of matrix:-
6
7
3
4
5
9
1
4
10
2
Original Matrix
67
34
59
14
10 2
Sorted Matrix
12
34
45
67
9 10
COMPUTER PROJECT 9
PROGRAM - 3
Write a program in java to input a square matrix. Display the original
matrix and the numbers are present in diagonals.
Source Code:
import java.util.Scanner;
public class Q3
{
int [][]num;
public void input()
{
Scanner in = new Scanner(System.in);
System.out.print("Enter the number of rows: ");
int r = in.nextInt();//taking input number of rows
System.out.print("Enter the number of columns: ");
int m = in.nextInt();//taking input number of rows
if(r!=m)//checking if square matrix
{
System.out.println("Rows and columns do not match");
System.exit(0);
}
num = new int[r][m];
System.out.println("Enter the elements of matrix");//taking input numbers in matrix
for(int i=0;i<r;i++)
{
for(int j=0;j<m;j++)
{
num[i][j]=in.nextInt();
}
}
}
public void show()
{
System.out.println("Original Matrix");
for(int i=0;i<num.length;i++)
{
for(int j=0;j<num[i].length;j++)
{
System.out.print(num[i][j]+" ");
}
System.out.println();
}
System.out.println("Numbers in Diagonals");
int j = 0;
COMPUTER PROJECT 10
for(int i = 0; i < num.length;i++)
{
System.out.print(num[i][j]+"\t");
j++;
}
j = num[0].length-1;
System.out.println();
for(int i = 0; i < num.length;i++)
{
System.out.print(num[i][j]+"\t");
j--;
}
}
}
VARIABLE DESCRIPTION
NAME TYPE PURPOSE
num int[][] To store the matrix
in Scanner Scanner object for input
r int To store number of rows
m int To store number of columns
i int Loop Counter
j int Loop Counter
OUTPUT:
Enter the number of rows: 3
Enter the number of columns: 3
Enter the elements of matrix
1
2
3
4
5
6
7
8
9
Original Matrix
123
456
789
COMPUTER PROJECT 11
Numbers in Diagonals
1 5 9
3 5 7
COMPUTER PROJECT 12
PROGRAM - 4
Write a program in java to input a matrix and arrange all the elements of
each row in ascending order. Also display the original matrix.
SOURCE CODE:
import java.util.Scanner;
public class Q4
{
int [][]num;
public void input()
{
Scanner in = new Scanner(System.in);
System.out.print("Enter the number of rows: ");
int r = in.nextInt();//taking input number of rows
System.out.print("Enter the number of columns: ");
int m = in.nextInt();//taking input number of columns
num = new int[r][m];
System.out.println("Enter the elements of matrix:-");
for(int i=0;i<r;i++)//taking input numbers of matrix
{
for(int j=0;j<m;j++)
{
num[i][j]=in.nextInt();
}
}
}
public void ArrRow(int [][]matrix)//arranging rows
{
for (int i = 0; i < matrix.length; i++)
{
for (int j = 0; j < matrix[i].length - 1; j++)
{
for (int k = 0; k < matrix[i].length - 1 - j; k++)
{
if (matrix[i][k] > matrix[i][k + 1])
{
int temp = matrix[i][k];
matrix[i][k] = matrix[i][k + 1];
matrix[i][k + 1] = temp;
}
}
}
}
}
COMPUTER PROJECT 13
public void show()
{
System.out.println("Original Matrix:-");
for(int i=0;i<num.length;i++)
{
for(int j=0;j<num[i].length;j++)
{
System.out.print(num[i][j]+" ");
}
System.out.println();
}
System.out.println("Matrix after arranged rows:- ");
ArrRow(num);
for(int i=0;i<num.length;i++)
{
for(int j=0;j<num[i].length;j++)
{
System.out.print(num[i][j]+" ");
}
System.out.println();
}
}
}
VARIABLE DESCRIPTION
NAME TYPE PURPOSE
num int[][] To store the matrix
in Scanner Scanner object for input
r int To store number of row
m int To store number of columns
i int Loop Counter
j int Loop Counter
k int Loop Counter
matrix int[][] To store matrix as argument
temp int Temporary buffer
COMPUTER PROJECT 14
OUTPUT:
Enter the number of rows: 3
Enter the number of columns: 3
Enter the elements of matrix:-
9
8
7
1
2
3
6
5
4
Original Matrix:-
987
123
654
Matrix after arranged rows:-
789
123
456
COMPUTER PROJECT 15
PROGRAM - 5
Write a program in java to input a string and replace all the occurrences
of a particular word by another word.
SOURCE CODE:
import java.util.Scanner;
public class Q5
{
String str, w1,w2;
public void input()
{
Scanner in = new Scanner(System.in);
System.out.print("Enter the string: ");
str = in.nextLine();//taking input the string
System.out.print("Enter the word to be replaced: ");
w1 = in.nextLine();//taking input word to be replaced
System.out.print("Enter the word to replace with: ");
w2 = in.nextLine();//taking input word to replace with
}
public String Replace()//function to replace
{
str = str + " ";
String temp = "";
String str2 = "";
for(int i = 0; i < str.length(); i++)
{
if(str.charAt(i) != ' ')
{
temp = temp + str.charAt(i);
}
else
{
if(temp.equals(w1))
str2 = str2.concat(" ")+w2;
else
str2 = str2.concat(" ")+temp;
temp = "";
}
}
return str2.trim();
}
public void show()
{
COMPUTER PROJECT 16
System.out.println("New String:-");
System.out.println(Replace());
}
}
VARIABLE DESCRIPTION
NAME TYPE PURPOSE
str String To store original string
w1 String To store word to be replaced
w2 String To store word to replace
with
temp String To act as buffer
str2 String To store new String
in Scanner Scanner object for input
i int Loop Counter
OUTPUT:
Enter the string: My country is a great country
Enter the word to be replaced: country
Enter the word to replace with: nation
New String:-
My nation is a great nation
COMPUTER PROJECT 17
PROGRAM - 6
Write a program in java to input a word and display a new word after
removing all repeated letters.
SOURCE CODE:
import java.util.Scanner;
public class Q6
{
String str, str2;
public void input()
{
Scanner in = new Scanner(System.in);
System.out.print("Enter Word: ");//taking input the word
str = in.nextLine();
str = str.toUpperCase();
}
public void show()
{
str2 = "";//variable to store new word
for(int i=0; i<str.length(); i++)
{
if(str2.indexOf(str.charAt(i))>=0)
continue;
else
str2 += str.charAt(i);
}
System.out.println("New Word: "+str2);//displaying the word
}
}
VARIABLE DESCRIPTION
NAME TYPE PURPOSE
str String To store the word
str2 String To store new word
in Scanner Scanner object for input
i int Loop Counter
OUTPUT:
Enter Word: Applications
New Word: APLICTON
COMPUTER PROJECT 18
PROGRAM - 7
Write a program in java in input a sentence and display the new sentence
in toggle case.
SOURCE CODE:
import java.util.Scanner;
public class Q7
{
String str;
public void input(){
Scanner in = new Scanner(System.in);
System.out.println("Enter Sentence: ");//taking input the sentence
str = in.nextLine();
}
public void show()
{
int a;
for(int i = 0; i<str.length(); i++)//changing case of each letter and printing it
{
if(Character.isLetter(str.charAt(i)))//checking if character is a letter
{
a = (int)str.charAt(i);
if(Character.isUpperCase(str.charAt(i)))
a = a+32;
else
a = a-32;
System.out.print((char)a);
}
else
System.out.print(str.charAt(i));
}
}
}
VARIABLE DESCRIPTION
NAME TYPE PURPOSE
str String To store the sentence
a int To store ASCII values and
change cases
i int Loop Counter
OUTPUT:
Enter Sentence:
Compuuters Are The FUTURE
cOMPUUTERS aRE tHE future
COMPUTER PROJECT 19
PROGRAM - 8
Write a program in java to input a word and display the following
pattern:-
S
SI
SIM
SIMP
SIMPL
SIMPLE
SIMPL
SIMP
SIM
SI
S
SOURCE CODE:
import java.util.Scanner;
public class Q8
{
String str;
public void input(){
Scanner in = new Scanner(System.in);
System.out.println("Enter Word: ");//taking input word for pattern
str = in.nextLine();
}
public void show()//function to display pattern
{
for(int i=0;i<str.length();i++)//first half of pattern
{
for(int j = 0; j<=i; j++)
{
System.out.print(str.charAt(j)+ " ");
}
System.out.println();
}
for(int i = str.length()-2; i>=0; i--)//second half of pattern
{
for(int j = 0; j<=i; j++)
{
System.out.print(str.charAt(j)+ " ");
}
System.out.println();
}
}
}
COMPUTER PROJECT 20
VARIABLE DESCRIPTION
NAME TYPE PURPOSE
str String To store the word
in Scanner Scanner object for input
i int Loop Counter
j int Loop Counter
OUTPUT:
S
SI
SIM
SIMP
SIMPL
SIMPLE
SIMPL
SIMP
SIM
SI
S
COMPUTER PROJECT 21
PROGRAM - 9
Write a program in java to input a String and encode the String by the
following pattern:
SAMPLE INPUT: ABCXYZ
SAMPLE OUTPUT: CDEZAB
Source Code:
import java.util.Scanner;
public class Q9
{
String str;
public void input()
{
Scanner in = new Scanner(System.in);
System.out.print("Enter String: ");//taking input the String
str = in.nextLine();
}
public void show()
{
String str2 = "";//New string
for(int i=0; i<str.length(); i++)//encoding the string
{
int a = (int)str.charAt(i);
if((a+2)>90)
{
a = (a+2)-90;
a = 64+a;
}
else
{
a = a+2;
}
str2 += (char)a;
}
System.out.println("Encoded String: "+str2);//displaying the encoded String
}
}
COMPUTER PROJECT 22
VARIABLE DESCRIPTION
NAME TYPE PURPOSE
str String To store the string
in Scanner Scanner object for input
str2 String To store encoded string
i int Loop Counter
a int Buffer to encode
OUTPUT:
Enter String: EFGUVW
Encoded String: GHIWXY
COMPUTER PROJECT 23
PROGRAM - 10
Write a program in java to input a string and display all the palindrome
words from it. Also display the length of the palindrome word whose size
is maximum.
Source Code:
import java.util.Scanner;
public class Q10
{
String str;
public void input()
{
Scanner in = new Scanner(System.in);
System.out.print("Enter String: ");
str = in.nextLine();//taking input the String
}
public boolean isPalindrome(String w)//function to check if word is palindrome
{
String temp = "";
for(int i = w.length()-1; i >= 0; i--)
{
temp += w.charAt(i);
}
return temp.equals(w);
}
public void show()//showing palindrome words
{
String temp = "";
str = str + " ";
int f = 0, l = 0;
System.out.println("Output:- ");
for(int i = 0; i < str.length(); i++)
{
if(str.charAt(i) != ' ')
temp += str.charAt(i);
else
{
if(isPalindrome(temp))
{
f++;
System.out.println(f+". "+temp);
if(temp.length()>l)
COMPUTER PROJECT 24
l = temp.length();
}
temp = "";
}
}
if(f == 0)//if there are no palindrome words
System.out.println("There are no Palindrome Words");
else
System.out.println("Size of longest Palindrome Word = "+ l);
}
}
VARIABLE DESCRIPTION
NAME TYPE PURPOSE
str String To store the sentence
in Scanner Scanner object for input
w String To store word as argument
temp String Word buffer
i int Loop Counter
f int To check if palindrome word
exists
l int To store length of longest
palindrome word
OUTPUT:
Enter String: Madam, Hannah, and Otto found a level radar
Output:-
1. a
2. level
3. radar
Size of longest Palindrome Word = 5
COMPUTER PROJECT 25
CONCLUSION
In conclusion, this Java programming project showcases the practical application of
fundamental programming concepts in building efficient and functional software
solutions. Through the implementation of various features and algorithms, it
demonstrates the versatility and power of Java as a programming language. By
addressing specific problem statements and delivering viable solutions, this project
underscores the importance of meticulous planning, systematic development, and
rigorous testing in software development processes. Overall, this project serves as a
testament to the capabilities of Java programming in solving real-world problems and
lays a solid foundation for further exploration and innovation in the field of computer
science.
COMPUTER PROJECT 26