# COmputer Project 2020-21 class x

```COMPUTER PROJECT
Name : ANKAN GHOSH
Class : Xi
section : A
Roll no. : 10
School : TRIBENI TISSUES VIDYAPITH
ACKNOWLEDGEMENT
I would like to express my special thanks of
gratitude to my teacher Avishek Paul as well as
our principal Ms. Sanghamitra Chatterjee who
gave me the golden opportunity to do this
wonderful project on the topic Java programming
which also helped me in doing a lot of Research
and I came to know about so many new things, I
am really thankful to them.
Secondly I would also like to thank my parents
and friends who helped me a lot in finalizing this
project within the limited time frame.
CONTENT
Sl.No
Topic
Page.No
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
Program No.1
Program No.2
Program No.3
Program No.4
Program No.5
Program No.6
Program No.7
Program No.8
Program No.9
Program No.10
Program No.11
Program No.12
Program No.13
Program No.14
Program No.15
1-4
5-7
8-10
11-13
14-16
17-19
20-22
23-25
26-28
29-31
32-34
35-37
38-40
41-42
43-45
QUESTION 1:
Write a program to find the maximum and minimum element and print the
sorted 2D array.
CODE:
import java.util.*;
public class Q1
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.print(&quot;ENTER THE NUMBER OF ROWS IN THE MATRIX:&quot;);
int r = sc.nextInt();
System.out.print(&quot;ENTER THE NUMBER OF COLUMNS IN THE MATRIX:&quot;);
int c = sc.nextInt();// Prepare matrix
System.out.println(&quot;ENTER THE ELEMENTS OF THE MATRIX : &quot;);
int matrix[][] = new int[r][c];
for(int i = 0; i &lt; r; i++)
{
for(int j = 0; j &lt; c; j++)
{
matrix[i][j] = sc.nextInt();
}
}
System.out.println(&quot;ENTERED MATRIX:&quot;);
for(int i = 0; i &lt; r; i++)
{
for(int j = 0; j &lt; c; j++)
{
System.out.print(&quot; &quot; +matrix[i][j]+&quot;\t&quot;);
}
System.out.println();
}// call method to find min and max in matrix
findMinAndMax(matrix);
}// Method to find maximum and minimum in matrix
private static void findMinAndMax(int[][] matrix)
{
int max = matrix[0][0];
int min = matrix[0][0];
for (int i = 0; i &lt; matrix.length; i++)
{
for (int j = 0; j &lt; matrix[i].length; j++)
{
if(max &lt; matrix[i][j])
{
max = matrix[i][j];
}
else if(min &gt; matrix[i][j])
{
min = matrix[i][j];
}
}
}
System.out.println(&quot;THE MAX NUMBER IN THE MATRIX:&quot; + max);
System.out.println(&quot;THE MIN NUMBER IN THE MATRIX:&quot; + min);
}
}
VARIABLE DESCRIPTION:
VARIABLE
TYPE
DESCRIPTION
r
int
c
int
i
int
to store the value of the
no. of rows.
to store the value of the
no. of columns.
for loop variable
j
int
for loop variable
min
int
to store the value of the
min variable
max
int
matrix
int[]
to store the value of max
variable
2D array to create a
matrix
OUTPUT SCREEN:
QUESTION 2:
Write a program to sort and print boundary element.
CODE:
import java.util.*;
class Q2
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
System.out.print(&quot;ENTER THE ROWS OF THE MATRIX:&quot;);
int r = sc.nextInt();
System.out.print(&quot;ENTER THE COLUMNS OF THE MATRIX:&quot;);
int c = sc.nextInt();
int a[][] = new int[r][c];
int i,j;
System.out.println(&quot;ENTER THE ELEMENTS OF THE MATRIX:&quot;);
for(i = 0; i &lt; r; i++)
{
for(j = 0; j &lt; c; j++)
{
a[i][j]=sc.nextInt();
}
}
System.out.println(&quot;THE MATRIX IS:&quot;);
for(i = 0; i &lt; r; i++)
{
for(j = 0; j &lt; c; j++)
{
System.out.print(a[i][j]+&quot;\t&quot;);
}
System.out.println();
}
int B[] = new int[r*c]; //creating a 1D Array of size 'r*c'
int x = 0;
for(i = 0; i &lt; r; i++)
{
for(j = 0; j &lt; c; j++)
{
B[x] = a[i][j];
x++;
}
}//Sorting the 1D Array in Ascending Order
int t = 0;
for(i = 0; i &lt; (r * c) - 1; i++)
{
for(j = i + 1; j &lt; (r * c); j++)
{
if(B[i] &gt; B[j])
{
t = B[i];
B[i] = B[j];
B[j] = t;
}
}
}//Saving the sorted 1D Array back into the 2D Array
x = 0;
for(i = 0; i &lt; r; i++)
{
for(j = 0; j &lt; c; j++)
{
a[i][j] = B[x];
x++;
}
}//Printing the sorted 2D Array
System.out.println(&quot;THE SORTED ARRAY:&quot;);
for(i = 0; i &lt; r; i++)
{
for(j = 0; j &lt; c; j++)
{
System.out.print(a[i][j]+&quot;\t&quot;);
}
System.out.println();
}
System.out.println(&quot;THE BOUNDARY ELEMENTS OF THE MATRIX ARE:&quot;);
for(i = 0; i &lt; r; i++)
{
for(j = 0; j &lt; c; j++)
{
if(i==0 || j==0 || i == r-1 || j == c-1) //condition for accessing boundary elements
System.out.print(a[i][j]+&quot;\t&quot;);
else
System.out.print(&quot; \t&quot;);
}
System.out.println();
}
}
}
VARIABLE DESCRIPTION:
VARIABLE
m,n
TYPE
int
i,j
a[]
B[]
t
int
int[]
int[]
int
DESCRIPTION
to store the value of rows
and columns
for loop variables
to make 2D array
1D array
temp variable for replace
variable
OUTPUT SCREEN:
QUESTION 3:
Write a program to calculate the saddle point in 2D array.
CODE:
import java.util.*;
class Q3
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.print(&quot;ENTER THE SIZE OF THE MATRIX:&quot;);
int m=sc.nextInt();
int a[][]=new int[m][m];//Inputting the matrix
for(int i=0;i&lt;m;i++)
{
for(int j=0;j&lt;m;j++)
{
System.out.print(&quot;ENTER AN ELEMENT(&quot;+i+&quot;,&quot;+j+&quot;):&quot;);
a[i][j]=sc.nextInt();
}
}//Printing the matrix
System.out.println(&quot;THE MATRIX IS:&quot;);
for(int i=0;i&lt;m;i++)
{
for(int j=0;j&lt;m;j++)
{
System.out.print(a[i][j]+&quot;\t&quot;);
}
System.out.println();
}
int min,max,c,flag=0;
for(int i=0;i&lt;m;i++)
{
min=a[i][0];
c=0;
for(int j=0;j&lt;m;j++)
{
if(a[i][j]&lt;min)
{
min=a[i][j];
c=j;
}
}
max=a[0][c];
for(int k=0;k&lt;m;k++)
{
if(a[k][c]&gt;max)
{
max=a[k][c];
}
}
if(max==min)
{
flag=1;
}
}
if(flag==0)
{
}
}
}
VARIABLE DESCRIPTION:
VARIABLE
x,y
i
TYPE
int
int
DESCRIPTION
method variables
for loop variable
hcf
int
to store the HCF
a,b
int
main() variables taken
input to find HCF
OUTPUT SCREEN:
QUESTION 4:
Write a Program to check for Symmetric matrix.
CODE:
import java.util.*;
class Q4
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.print(&quot;ENTER THE NUMBER OF ELEMENTS:&quot;);
int m=sc.nextInt();
int a[][]=new int[m][m];
if(m&gt;2 &amp;&amp; m&lt;10)// Checking for valid input of rows and columns size
{
System.out.println(&quot;ENTER THE ELEMENTS:&quot;);
for(int i=0;i&lt;m;i++)
{
for(int j=0;j&lt;m;j++)
{
a[i][j]=sc.nextInt();
}
}
System.out.println(&quot;THE MATRIX IS:&quot;);
for(int i=0;i&lt;m;i++)
{
for(int j=0;j&lt;m;j++)
{
System.out.print(a[i][j]+&quot;\t&quot;);
}
System.out.println();
}
int flag = 0;
for(int i=0;i&lt;m;i++)
{
for(int j=0;j&lt;m;j++)
{
if(a[i][j] != a[j][i])
{
flag = 1;
break;
}
}
}
if(flag == 1)
System.out.println(&quot;THE GIVEN MATRIX IS NOT SYMMETRIC&quot;);
else
System.out.println(&quot;THE GIVEN MATRIX IS SYMMETRIC&quot;);
}
}
}
VARIABLE DESCRIPTION:
VARIABLE
first
second
TYPE
int
int
DESCRIPTION
1 value of the series
2nd value of the series
third
int
3rd value of the series
n
int
while loop variable
OUTPUT SCREEN:
st
QUESTION 5:
Write A Program To generate the mirror image of 2D array.
CODE:
import java.util.*;
class Q5
{
int a[][],b[][],m;
void input()
{
Scanner sc=new Scanner(System.in);
System.out.print(&quot;ENTER THE SIZE OF THE MATRIX:&quot;);
m=sc.nextInt();
a=new int [m][m];b=new int [m][m];
System.out.println(&quot;ENTER THE ELEMENTS:&quot;);
for(int i=0;i&lt;m;i++)
{
for(int j=0;j&lt;m;j++)
{
a[i][j]=sc.nextInt();
}
}
}
void Calculate()
{
int i,j,k,l;
for(i=0;i&lt;m;i++)
{
for(j=0;j&lt;m;j++)
{
for(k=0;k&lt;m;k++)
{
if((j+k)==(m-1))
b[i][k]=a[i][j];
}
}
}
}
void Output()
{
int i,j;
for(i=0;i&lt;m;i++)
{
for(j=0;j&lt;m;j++)
{
System.out.print(b[i][j]+&quot; &quot;);
}
System.out.println();
}
}
void output2()
{
int i,j;
for(i=0;i&lt;m;i++)
{
for(j=0;j&lt;m;j++)
{
System.out.print(a[i][j]+&quot; &quot;);
}
System.out.println();
}
}
public static void main(String args[])
{
Q5 ob=new Q5();
ob.input();
System.out.println(&quot;THE MATRIX IS:&quot;);
ob.output2();
System.out.println(&quot;THE MIRROR MATRIX IS:&quot;);
ob.Calculate();
ob.Output();
}
}
VARIABLE DESCRIPTION:
VARIABLE
num
f
i
TYPE
int
int
int
DESCRIPTION
constructor initialisation
constructor initialisation
for loop variable
OUTPUT SCREEN:
QUESTION 6:
Define a class result described as below:
Data members I instance variables:
name,s1 , s2, s3 (marks in 3 subjects), maximum, Member methods
(i)result ()- A parameterized constructor to initialize the data members
(ii)void accept()- To accept the details of a student
(iii)void Compute()- To compute the maximum out of three marks
(iv) void display()-To display the name, marks in three subjects, maximum and
Write a main method to create an object of a class and call the above member
methods.
CODE:
import java.util.*;
public class result
{
String n;
int s1,s2,s3,max;
void accept()//accepting the values
{
Scanner sc=new Scanner(System.in);
n = sc.nextLine();
System.out.print(&quot;ENTER YOUR MARKS IN 1ST SUBJECT:&quot;);
s1=sc.nextInt();
System.out.print(&quot;ENTER YOUR MARKS IN 2ND SUBJECT:&quot;);
s2=sc.nextInt();
System.out.print(&quot;ENTER YOUR MARKS IN 3RD SUBJECT:&quot;);
s3=sc.nextInt();
}
void Compute()//calculating the maximum
{
max=Math.max(s1,Math.max(s2,s3));
}
void display()//displaying the details
{
System.out.println(&quot;THE MAXIMUM MARKS IS:&quot; +max);
}
public static void main(String[]args)//invoking main()
{
result op=new result();
op.accept();
op.Compute();// calling the methods
op.display();
}}
VARIABLE DESCRIPTION:
VARIABLE
name
s1
s2
s3
max
TYPE
String
int
int
int
int
DESCRIPTION
To take input the name
1st subject marks
2nd subject marks
3rd subject marks
to store the maximum
marks
OUTPUT SCREEN:
QUESTION 7:
Write a program in java to initialize the following character arrays and print a
suitable message after checking the array whether the two arrays are identical or
not .
X[]={‘x’,’y’,’z’,’w’}
Y[]={‘x’,’y’,’z’,’w’}
CODE:
public class EQUALARRAYs
{
public static void main(String[]args)
{
char X[]={'x','y','z','w'};
char Y[]={'x','y','z','w'};
boolean res=true;
if(X.length==Y.length)
{
for(int i=0;i&lt;X.length;i++)
{
if(X[i]!=Y[i])
{
res=false;
}
}
}
else
{
res=false;
}
if(res==true)
{
System.out.println(&quot;ARRAYs ARE EQUAL&quot;);
}
else
{
System.out.println(&quot;ARRAYs ARE NOT EQUAL&quot;);
}
}
}
VARIABLE DESCRIPTION:
VARIABLE
TYPE
res
int
i
X[]
Y[]
int
char
char
DESCRIPTION
to store the Boolean
variable
for loop variable
array no. 1
array no. 2
OUTPUT SCREEN:
QUESTION 8:
Design a function void findMarks(float M[]).The function takes single subscripted
variable M[]as function arguments with marks of 10 students. Print average of 10
students along with highest and lowest marks scored by the students with
suitable messages.
code:
import java.util.*;
public class find
{
void findMarks(float M[])
{
float total=0;
for(int i=0;i&lt;M.length;i++)//to find the total
{
total=total+M[i];
}
float avg=total/10;//to find the average
System.out.println(&quot;The average is &quot; + avg);
float max=0,min=0;
max=min=M[0];
for(int j=0;j&lt;M.length;j++)//to find the max and min
{
if(M[j]&gt;max)
{
max=M[j];
}
if(M[j]&lt;min)
{
min=M[j];
}
}
System.out.println(&quot;The smallest element is&quot; + min);
System.out.println(&quot;The largest element is &quot; + max);
}
public static void main(String[]args)//invoking main()
{
Scanner sc=new Scanner(System.in);
find op=new find();
System.out.println(&quot;Enter 10 elements&quot;);
int n=10;
float m[]=new float[n];
for(int i=0;i&lt;m.length;i++)
{
m[i]=sc.nextFloat();
}
op.findMarks(m);//invoking the function
}
}
VARIABLE DESCRIPTION:
VARIABLE
TYPE
M[],m[]
float
total
avg
float
float
max,min
float
n
i
int
int
DESCRIPTION
to declare the arrays in
method and in main()
to store the total marks
to store the average of
the marks
to store the max and min
values
to store the array size
for loop variable
OUTPUT SCREEN:
PROGRAM 9:
CODE:
import java.util.*;
class Special_Number
{
int fact(int q)//to calculate the factorial
{
int f=1;
for(int i=1; i&lt;=q; i++){
f=f*i;
}
return f;
}
void printNumbers()//to calculate special numbers
{
int sum, i, j, fact,r;
System.out.println(&quot;Numbers between 10 and 200&quot;);
for( i=10; i&lt;=200; i++)
{
sum=0;
j=i;
while(j!=0)//calculating….
{
r=j%10;
fact=fact(r);
sum=sum+fact;
j=j/10;
}
if(sum==i)
System.out.println(i);
}
}
public static void main(String[] args)//invoking main()
{
Special_Number ob=new Special_Number();
ob.printNumbers();
}}
VARIABLE DESCRIPTION:
VARIABLE
TYPE
q
f
i
j
r
int
int
int
int
int
fact
int
DESCRIPTION
method variable
method factorial variable
for loop variable
for loop variable
to calculate the
remainder
to calculate the factorial
OUTPUT SCREEN:
QUESTION 10:
CODE:
import java.util.*;
class swapping{
int a,b;
void swap(swapping obj)
{
obj.a=obj.a+obj.b;
obj.b=obj.a-obj.b;
obj.a=obj.a-obj.b;
}
public static void main(String[] args)
{
swapping obj=new swapping();
Scanner sc=new Scanner(System.in);
System.out.print(&quot;ENTER A:&quot;);
obj.a=sc.nextInt();
System.out.print(&quot;ENTER B:&quot;);
obj.b=sc.nextInt();
System.out.println(&quot;BEFORE INTERCHANGING:&quot;);
System.out.println(&quot;A = &quot;+obj.a);
System.out.println(&quot;B = &quot;+obj.b);
obj.swap(obj);
System.out.println(&quot;AFTER INTERCHANGING:&quot;);
System.out.println(&quot;A = &quot;+obj.a);
System.out.println(&quot;B = &quot;+obj.b);
}
}
VARIABLE DESCRIPTION:
VARIABLE
a,b
TYPE
int
DESCRIPTION
to store the swapped
numbers
OUTPUT SCREEN:
QUESTION 11:
Write a program in Java to input n integer elements in an array, sort them in
ascending order using the Bubble sort technique and display.
CODE:
import java.util.*;
class BubbleSort
{
public static void main (String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println(&quot;ENTER THE TOTAL SIZE OF THE ARRAY:&quot;);
int n=sc.nextInt(); //accepting size of array
int arr[]=new int[n];//declaring array
int i,j,temp;
System.out.println(&quot;ENTER ARRAY ELEMENTS&quot;);
for (i = 0; i &lt; n; i++)
{
arr[i]=sc.nextInt();//accepting array elements
}
System.out.println(&quot;INPUT:&quot;);
for (i = 0; i &lt; n; i++)
{
System.out.print (arr[i] + &quot;\t&quot;);
}
System.out.println();
for (i = 0; i &lt; n-1; i++)
{
for (j = 0; j &lt; n-i-1; j++)
{
if (arr[j] &gt; arr[j+1])//sorting array elements
{
temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
}
}
}
System.out.println(&quot;OUTPUT:&quot;);//displaying array elements
for (i = 0; i &lt; arr.length; i++)
{
System.out.print (arr[i] + &quot;\t&quot;);
}
} }
VARIABLE DESCRIPTION:
VARIABLE
TYPE
n
i,j
int
int
temp
arr
int
int[]
DESCRIPTION
Store size of array
Loop variables to count
array index
Store temporary value
Store integers
OUTPUT SCREEN:
QUESTION 12:
Write a program to search a number from a set of integers using linear search.
CODE:
import java.io.*;
class LinearSearch
{
public static void main(String args[])throws IOException
{
System.out.println(&quot;ENTER THE TOTAL SIZE OF THE ARRAY:&quot;);
int arr[]=new int[n];
int i,key;
System.out.println(&quot;ENTER ARRAY ELEMENTS&quot;);
for (i = 0; i &lt; n; i++)
{
}
System.out.print(&quot;ENTER THE INTEGER TO SEARCH:&quot;);
System.out.println(&quot;INPUT ARRAY:&quot;);
for (i = 0; i &lt; n; i++)
{
System.out.print (arr[i] + &quot;\t&quot;);
}
System.out.println();
for(i=0;i&lt;arr.length;i++)//searching process
{
if(key==arr[i])
break;
}
if(i==n)
else
System.out.println(key+&quot; found at index &quot;+i);
}
}
VARIABLE DESCRIPTION:
VARIABLE
TYPE
n
int
i
key
arr
int
int
int[]
DESCRIPTION
To store the size of the
array
Loop counter
Value to be searched
Store integers
OUTPUT SCREEN:
QUESTION 13:
Write a program to input a sentence and display the number of spaces, vowels
and words present in it.
CODE:
import java.util.*;
class Sentence
{
public static void main (String args[])
{
int len,i,blank=0,vowel=0;
char ch;
Scanner sc=new Scanner(System.in);
System.out.println(&quot;ENTER A SENTENCE:&quot;);
String str=sc.nextLine();//accepting the sentence
len=str.length();//calculate the length
str=str.toUpperCase();//convert the input to uppercase
for (i = 0; i &lt; len; i++)
{
ch=str.charAt(i);
if(ch==' ')
blank++;//count spaces
else
if(ch=='A'||ch=='E'||ch=='I'||ch=='O'||ch=='U')
vowel++;//count vowel
}
System.out.println(&quot;No. OF BLANK SPACES:&quot;+blank);
System.out.println(&quot;No. OF WORDS:&quot;+(blank+1));
System.out.println(&quot;No. OF VOWELS:&quot;+vowel);
}
}
VARIABLE DESCRIPTION:
VARIABLE
TYPE
str
len
String
int
i
blank
vowel
ch
int
int
int
char
DESCRIPTION
To store the sentence
To store the length of the
sentence
Loop counter
To calculate the spaces
To calculate the vowels
Temporary variable to
store character
OUTPUT SCREEN:
QUESTION 14:
Write a program to check whether a string is a palindrome or not. A palindrome
string that reads the same from left to right and vice versa eg. MADAM, ARORA,
CODE:
import java.util.*;
class Palindrome
{
public static void main (String args[])
{
int len,i;
char ch;
String str,rev=&quot;&quot;;
Scanner sc=new Scanner(System.in);
System.out.println(&quot;ENTER THE STRING:&quot;);
str=sc.nextLine();//accepting the string
len=str.length();
for (i=len-1; i&gt;=0; i--)//loop starting from end of the string
{
ch=str.charAt(i);//to store every character
rev=rev+ch;//to store in a reverse way
}
if(rev.equalsIgnoreCase(str))
System.out.println(&quot;IT IS A PALINDROME&quot;);
else
System.out.println(&quot;IT IS NOT A PALINDROME&quot;);
}
}
VARIABLE DESCRIPTION:
VARIABLE
TYPE
str
len
String
int
ch
char
i
rev
int
int
OUTPUT SCREEN:
DESCRIPTION
To store the sentence
To store the length of the
sentence
Temporary variable to store
character
Loop counter
To store the reverse of the string
QUESTION 15:
Write a program to accept a name and print only the first letter of each word of
the sentence in capital letters separated by a full stop.
Sample Input : “Mohandas Karamchand Gandhi”
Output : M.K.G.
CODE:
import java.util.*;
class Letters
{
public static void main (String args[])
{
String str;
int len,i;
char ch;
Scanner sc=new Scanner(System.in);
System.out.print(&quot;ENTER A NAME:&quot;);//accepting the sentence
str=sc.nextLine();
len=str.length();
System.out.println(&quot;THE ENTERED STRING IS:&quot;+str);
System.out.println(&quot;OUTPUT:&quot;);
System.out.print(Character.toUpperCase(str.charAt(0))+&quot;.&quot;);//prints the first
character along with '.'
for (i = 0; i &lt; len; i++)
{
ch=str.charAt(i);
if(ch==' ')//if space found
System.out.print(Character.toUpperCase(str.charAt(i+1))+&quot;.&quot;);//prints the next
character
}
System.out.println();
}
}
VARIABLE DESCRIPTION:
VARIABLE
TYPE
str
len
String
int
ch
char
i
rev
int
int
DESCRIPTION
To store the sentence
To store the length of the
sentence
Temporary variable to store
character
Loop counter
To store the reverse of the string
OUTPUT SCREEN:
CONCLUSION
This Project has been made for eduction purposes on Java
Programming .Java has significant advantages not only as a
commercial language but also as a teaching language. It
allows students to learn object-oriented programming
without exposing them to the complexity of C++. It provides
the kind of rigorous compile-time error checking typically
associated with Pascal. It allows instructors to introduce
students to GUI programming, networking, threads, and
other important concepts used in modern-day software.
While making this project I have came over many new
things , techniques which have helped me decrease my
mistakes.
```