S. L.
BAJORIA FOUNDATION HIGH SCHOOL
ACADEMIC YEAR 2025 - 26
COMPUTER APPLICATIONS PRACTICAL FILE ASSIGNMENT 1
GRADE - X
Topic – One Dimensional Arrays
11. Write a program to perform Binary Search on a list of integers give below, to search for a
key element input by the user. If it is found, display the element along with the position,
otherwise display the message “Search element is not found”.
int[ ] arr = {12,14,-10,56,79,90,22,99,109,81,103,221}
Source Code of Program No. 11
import [Link];
class BinarySearch
{
public static void main(String a[])
{
int[ ] arr={12,14,-10,56,79,90,22,99,109,81,103,221};
int key;
int i,j,n,temp;
Scanner scn=new Scanner([Link]);
[Link]("Displaying the given unsorted array list");
for(i=0;i<[Link];i++)
{
[Link](arr[i] + "\t");
}
//*************Bubble Sort***************
n=[Link];
for(i=0;i<n;i++)
{
for(j=1;j<(n-i);j++)
{
if(arr[j-1]>arr[j])
{
temp=arr[j-1];
arr[j-1]=arr[j];
arr[j]=temp;
}
}
}
[Link]("\nDisplaying the sorted array list");
for(i=0;i<[Link];i++)
{
[Link](arr[i] + "\t");
}
//******************Bubble Sort ends ***********************
1
[Link]("\nEnter the search key : ");
key=[Link]();
//***********Binary Search*****************
int ub,lb,mid;
boolean flag=false;
ub=[Link]-1;
lb=0;
mid=-1;
while(lb<=ub && flag==false)
{
mid=(lb+ub)/2;
if(key==arr[mid])
{
flag=true;
break;
}
else if(key<arr[mid])
ub=mid-1;
else
lb=mid+1;
}//while
if(flag==true)
{
[Link]("\nBinary Search Successful.....");
[Link]("\nThe search key element is found in location " + (mid+1));
}
else
{
[Link]("\nKey is not found. Search is not successful.....");
}
//*************** Binary Search ends **********************
}
}
2
Input / Output of Program No. 11
Variable Description Table of Program No. 11
Variable Names Data Type Purpose
arr[ ] int Array to store integer elements
i int Loop variable
j int Loop variable
n Int Stores the array size
temp int Temporary variable
lb int Stores the lower bound index
ub int Stores the upper bound index
mid int Stores the mid index
flag int Stores the flag value – 0 or 1
12. Write a program in Java that sorts the array of alphabets in descending order using Bubble
Sort technique. alpha={'B','d','m','p','A','t','E','Q','L','r','s','g'};
Source Code of Program No. 12
public class BubbleSortDesc
{
public static void main()
{
int i,j;
char[] alpha={'B','d','m','p','A','t','E','Q','L','r','s','g'};
int n=[Link];
char temp='\u0000';
[Link]("Displaying the unsorted array.");
for(i=0;i<n;i++)
[Link](alpha[i] + " ");
3
//======== Bubble Sort Ascending===========
for(i=0;i<n;i++)
{
for(j=1;j<n-i;j++)
{
if(alpha[j-1]<alpha[j])
{
temp=alpha[j-1];
alpha[j-1]=alpha[j];
alpha[j]=temp;
}
}
}
[Link]("\nDisplaying the sorted array in descending order.");
for(i=0;i<n;i++)
[Link](alpha[i] + " ");
}
}
Input / Output of Program No. 12
Variable Description Table of Program No. 12
Variable Names Data Type Purpose
alpha[ ] int Array to store character elements
i int Loop variable
j int Loop variable
n Int Stores the array size
temp int Temporary variable
4
13. Write a program to initialize the seven Wonders of the World along with their locations in
two different arrays. Search for a name of the country input by the user. If found, display
the name of the country along with its Wonder, otherwise display “Sorry Not Found!”.
Seven wonders - CHICHEN ITZA, CHRIST THE REDEEMER, TAJ MAHAL, GREAT WALL OF
CHINA, MACHU PICCHU, PETRA and COLOSSEUM
Locations - MEXICO, BRAZIL, INDIA, CHINA, PERU, JORDAN, ITALY
Example - Country Name: INDIA Output: INDIA - TAJMAHAL
Country Name: USA Output: Sorry Not Found!
Source Code of Program No. 13
package Grade_X.[Link];
import [Link];
public class SevenWonders
{
public static void main()
{
String[] SevenWonders={"CHICHEN ITZA","CHRIST THE REDEEMER", "TAJ MAHAL",
"GREAT WALL OF CHINA", "MACHU PICCHU",
"PETRA","COLOSSEUM"};
String[] Locations={"MEXICO","BRAZIL","INDIA","CHINA","PERU","JORDAN","ITALY"};
Scanner scn=new Scanner([Link]);
String key="";
int i,flag;
flag=0;
[Link]("Displaying the locations around the world...");
for(i=0;i<[Link];i++)
[Link](Locations[i] + " ");
[Link]("Enter your Location to search : ");
key=[Link]().toUpperCase();
for(i=0;i<[Link];i++)
{
if([Link](Locations[i]))
{
flag=1;
break;
}
}
if(flag==0)
[Link]("Sorry, not found!");
else
[Link](key+ " - " + SevenWonders[i]);
}
}
5
Input / Output of Program No. 13
Input / Output of Program No. 13
6
Variable Description Table of Program No. 13
Variable Names Data Type Purpose
SevenWonders[ ] String Array to store String elements of Seven Wonders
Locations[ ] String Array to store String elements of Locations
i int Loop variable
key String To store the key value to search
flag Int To store the flag value either 0 or 1
14. Write a program to accept names and total marks of N number of students in two single
subscript arrays name [ ] and totalmarks[ ]. Calculate and print:
(i) The average of the total marks obtained by N number of students.
[average = (sum of total marks of all the students)/N]
(ii) Deviation of each student’s total marks with the average.
[deviation = total marks of a student – average]
Source Code of Program No. 14
import [Link];
public class Deviation_Average
{
public static void main()
{
Scanner scn=new Scanner([Link]);
int N=0;
[Link]("Enter the total number of students : ");
N=[Link]();
String[] names=new String[N];
int[] TotalMarks=new int[N];
int sum,i;
double avg=0.0d;
avg=0.0f;
sum=0;
[Link]("\nEnter the student names and their total marks");
for(i=0;i<N;i++)
{
[Link]("\nEnter the name of student " + (i+1) + ":");
names[i]=[Link]();
[Link]("\nEnter the total marks of student " + (i+1) + ":");
TotalMarks[i]=[Link]();
sum=sum+TotalMarks[i];
}
avg=(double)sum/(double)N;
[Link]("The average of total marks obtained by " + N + " students = " +
avg);
[Link]("Computing the deviations of " + N + " students.");
for(i=0;i<N;i++)
7
[Link]("The deviation of " + names[i] + " = " + (TotalMarks[i] - avg));
}
}
Input / Output of Program No. 14
Variable Description Table of Program No. 14
Variable Names Data Type Purpose
TotalMarks[ ] String Array to store the total marks of the students
names[ ] String Array to store the names of the students
N int Stores the size of the array (No. of students)
I int Loop variable
sum Int Stores the sum of the total marks of N students
avg double Stores the average of total marks of N students
lb int Stores the lower bound index
ub int Stores the upper bound index
mid int Stores the mid index
flag int Stores the flag value – 0 or 1
8
15. Write a program in Java that creates a double array of size N to input and store the height of N
persons. Sort and display them in ascending order using the selection sort technique. The value of
N should be between 5 and 15.
Source Code of Program No. 15
package Grade_X.[Link];
import [Link];
public class SelectionSortAsc
{
public static void main()
{
Scanner scn=new Scanner([Link]);
int N,i,j,min;
double smallestNo;
N=0;
smallestNo=0.0d;
do
{
[Link]("Enter the value for N between 5 and 15 : ");
N=[Link]();
if(N<5 || N>15)
[Link]("Invalid input!");
}while(N<5 || N>15);
double[] arr=new double[N];
[Link]("Enter the height in (cms) of " + [Link] + " persons.");
//====== Storing array elements =====
for(i=0;i<[Link];i++)
{
[Link]("Enter the height of person " + (i+1) + ":");
arr[i]=[Link]();
}
//==========Selection Sort Ascending =======
for(i=0;i<[Link]-1;i++)
{
min=i;
for(j=i+1;j<[Link];j++)
{
if(arr[j]<arr[min])
{
min=j;
}
}//inner loop ends
smallestNo=arr[i];
arr[i]=arr[min];
9
arr[min]=smallestNo;
}//outer loop ends
[Link]("Displaying the heights (in cms) in ascending order.");
for(i=0;i<[Link];i++)
[Link](arr[i] + " ");
}
}
Input / Output of Program No. 15
Variable Description Table of Program No. 15
Variable Names Data Type Purpose
arr[ ] double Array to store the height of the N persons
N int Stores the size of the array N persons
i int Loop variable
j int Loop variable
min Int Stores the index of the smallest index
10
16. Design a class to overload a function area( ) as follows:
a. double area (double a, double b, double c) with three double arguments, returns the
area of a scalene triangle using the formula. Area= where s is
the half the perimeter. s=
b. double area (int a, int b, int height) with three integer arguments, returns the area of a
trapezium. Area= * height*(a+b)
c. double area(double diagonal1, double diagonal2) with two double arguments, returns
area of a rhombus using the formula : area = * (diagonal1 * diagonal2).
Source Code of Program No. 16
public class OverloadArea
{
public double area(double a,double b,double c)
{
double s,area1;
s=0.0;
area1=0.0;
s=(a+b+c)/2;
area1=[Link](s*(s-a)*(s-b)*(s-c));
return area1;
}
public double area(int a,int b, int height)
{
double area2=0.0;
area2=1/2.0*height*(a+b);
return area2;
}
public double area(double diagonal1,double diagonal2)
{
double area3=0.0;
area3=0.5*diagonal1*diagonal2;
return area3;
}
public static void main()
{
OverloadArea obj=new OverloadArea();
double area1=[Link](12.0d,12.5d,14.5d);
double area2=[Link](14,16,12);
double area3=[Link](7.5,7.0);
[Link]("Area of Scalene Triangle :: " + area1);
[Link]("Area of Trapezium :: " + area2);
[Link]("Area of Rhombus :: " + area3);
}
}
11
Input / Output of Program No. 16
Variable Description Table of Program No. 16
Variable Names Data Type Purpose
s double Stores the semi perimeter of a scalene triangle
area1 double Stores the area of a scalene triangle
area2 double Stores the area of a trapezium
area3 double Stores the area of a rhombus
a double Stores the first side of a scalene triangle
b double Stores the second side of a scalene triangle
c double Stores the third side of a scalene triangle
diagonal1 double Stores the first diagonal of a rhombus
diagonal2 double Stores the second diagonal of a rhombus
height int Stores the height of the trapezium
a int Stores the length of the first parallel side of a trapezium
b int Stores the length of second parallel side of a trapezium
17. Design a class to overload function series( ) as follows:
a. double Sum_Series(int a, int n) with two integer arguments. The first integer
argument a accepts the number of the series and the second integer argument
accepts the term of the series. The method returns the sum of the series.
sum= till n terms
b. void Sum_Series(int n) is a method with no arguments and computes the sum of the
series.
sum= + …… + till n terms.
Input / Output of Program No. 17
import [Link];
public class Overload1
{
public double Sum_Series(int a,int n)
{
double sum=0.0d;
int i,j,k,fact;
12
for(i=1,j=1;i<=n;i++,j+=2)
{
fact=1;
for(k=1;k<=j;k++)
{
fact=fact*k;
}
sum=sum + [Link](a,i)/(double)fact;
}
return sum;
}
public void Sum_Series(int n)
{
double sum=0.0d;
int i,j;
for(i=1,j=2;i<=n;i++,j+=2)
{
if(i%2==1)
sum+= (double)j/(double)(j+1);
else
sum-= (double)j/(double)(j+1);
}
[Link]("Sum series2 = " + sum);
}
public static void main()
{
Scanner scn=new Scanner([Link]);
int n,a;
[Link]("Enter value of a : ");
a=[Link]();
[Link]("Enter value of n : ");
n=[Link]();
Overload1 obj=new Overload1();
double s=obj.Sum_Series(a,n);
[Link]("Sum series1 = " + s);
obj.Sum_Series(n);
}
}
13
Input / Output of Program No. 17
Variable Description Table of Program No. 17
Variable Names Data Type Purpose
a int Formal parameter to store an integer value
n int Formal parameter to store the number of terms of a series
i int Loop variable
j int Loop variable
k int Loop variable
sum double Stores the sum of the series
fact Int Stores the factorial of a number
18. Design a class to overload a function called Number( ) as follows:
(i) void Number (int num , int d) - To count and display the frequency of a digit in a
number.
Example:
num = 2565685
d=5
Frequency of digit 5 = 3
(ii) int Number (int n1) - To find and display the sum of even digits of a number.
Example:
n1 = 29865
Sum of even digits = 16
Write a main method to create an object and invoke the above methods.
14
Source Code of Program No. 18
import [Link];
public class Overload2
{
public void Number(int num,int d)
{
int temp,digit,freq;
temp=num;
freq=0;
while(temp>0)
{
digit=temp%10;
if(digit==d)
freq++;
temp=temp/10;
}
[Link]("The frequency of the digit = " + freq);
}
public int Number(int n1)
{
int digit,sum;
sum=0;
while(n1>0)
{
digit=n1%10;
if(digit%2==0)
sum+=digit;
n1=n1/10;
}
return sum;
}
public static void main()
{
Scanner scn=new Scanner([Link]);
int n,d;
[Link]("Enter a number : ");
n=[Link]();
[Link]("Enter any digit in above specified number : ");
d=[Link]();
Overload2 obj=new Overload2();
[Link](n,d);
int sum= [Link](n);
[Link]("Sum of even digits= " + sum);
}
}
15
Input / Output of Program No. 18
Variable Description Table of Program No. 18
Variable Names Data Type Purpose
num int Formal parameter to store an integer value
d int Formal parameter to store the digit to be searched
temp int Temporary variable
digit int Stores the digit for which the frequency to be found
freq int Counter Variable
sum int Stores the sum of the even digits
19. Define a class to accept values into a 3×3 array and display the left diagonal and right
diagonal elements. Also, display the sum of left diagonal elements.
Example: A[][]={{ 8,9,10}, {23,45,67}, { 14, 12, 15}}; Sum of even elements = 4+6+2+4+2 =18
Sum of odd elements= 5+5+3+5=18.
Example:
Input: A[][]={{ 8,9,10}, {23,45,67}, { 14, 12, 15}}
Output:
8 10
45
14 15
Sum of left diagonal elements = 68
16
Source Code of Program No. 19
public class SumLeft_Right_Diagonal
{
public static void main()
{
int[][] A={{8,9,10},{23,45,67},{14,12,15}};
int i,j,sumLeft;
sumLeft=0;
[Link]("Displaying the original matrix");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
[Link](A[i][j] + "\t");
}
[Link]();
}
[Link]("\nDisplaying the left and right diagonal elements");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
if(i==j)
{
[Link](A[i][j] + "\t");
sumLeft+=A[i][j];
}
else if((i+j)==2)
{
[Link](A[i][j] + "\t");
}
else
[Link]("\t");
}
[Link]();
}
[Link]("Sum of left diagonal = " + sumLeft);
}
}
17
Input / Output of Program No. 19
Variable Description Table of Program No. 19
Variable Names Data Type Purpose
arr[][] int Two Dimensional Array
i int Loop Variable
j int Loop Variable
sumLeft int Stores the sum of the left diagonal elements
freq int Counter Variable
sum int Stores the sum of the even digits
20 Write a program which defines a two dimensional array of size m and n respectively. The
array stores integers input by a user. Display the elements of the 2 dimensional array in a
matrix form and also the sum of elements in each row. The value of m and n will be input by
a user and the range should be between 3 and 8.
Example - Input:
Enter the value of m: 4
Enter the value of n: 3
Output:
2 3 4 Sum of Row 1 = 9
5 7 9 Sum of Row 2 = 21
10 20 30 Sum of Row 3 = 60
11 22 33 Sum of Row 4 = 66
18
Source Code of Program No. 20
import [Link];
public class SumRows
{
private int[][] matrix; //2D array declaration
int rows,cols;
public SumRows(int r,int c) //formal parameters
{
[Link]=r; //initialize of number of rows
[Link]=c; //initialize of no. of columns
[Link]=new int[[Link]][[Link]]; //array is created
}
public void accept()
{
int i,j;
Scanner scn=new Scanner([Link]);
[Link]("Enter the array elements in " + [Link] + "x" + [Link] + " matrix,
row-wise");
for(i=0;i<[Link];i++)
{
[Link]("Enter elements of row " + (i+1));
for(j=0;j<[Link];j++)
{
[Link]("Enter array element " + (j+1) + ":");
[Link][i][j]=[Link]();
}
}
}
public void display()
{
int i,j,sum;
[Link]("Displaying the original matrix");
for(i=0;i<[Link];i++) //loop for row index
{
sum=0;
for(j=0;j<[Link];j++) //loop for column index
{
[Link]([Link][i][j] + "\t");
sum+=[Link][i][j];
}
[Link]("Sum of Row " + (i+1) + "=" + sum);
[Link]();
}
}
public static void main()
{
int x,y;
Scanner scn=new Scanner([Link]);
x=y=0;
do
19
{
[Link]("Enter the value of x between 3 and 12 : ");
x=[Link]();
[Link]("Enter the value of y between 3 and 12 : ");
y=[Link]();
if((x<3 || x>12) || (y<3 || y>12))
[Link]("Invalid input");
}while((x<3 || x>12) || (y<3 || y>12));
SumRows obj=new SumRows(x,y); //actcual parameters
[Link]();
[Link]();
}
}
Variable Description Table of Program No. 20
Variable Names Data Type Purpose
matrix [ ][ ] int Two Dimensional Array
rows int Stores the row size
cols int Stores the column size
r int Formal parameter
c int Formal parameter
sum int Stores the sum of the even digits
i int Loop Variable
j int Loop Variable
sum int Stores the sum of each row
20
Input / Output of Program No. 20
21
Input / Output of Program No. 20 (Continued)
22