Java Lab Journal Full
Java Lab Journal Full
Program 1: Program to implement dynamic array and find smallest & largest
element of the array
Objective: The goal of implementing a dynamic array to find the smallest and largest
elements is to create a data structure that can adjust its size based on the number of
elements stored in it. The flexibility allows it to efficiently determine the smallest and
largest elements within the array.
Theory: The smallest and largest elements in an array using a dynamic array means that
we create a resizable array structure that allows fast and efficient storage and retrieval
of data. By dynamically adjusting the size of the array as needed, we can ensure that the
smallest and largest elements are effectively managed. The usual way is to:
1) Create a dynamically resizable array structure with fields like size and capacity.
2) Implement function to add elements to the array and resize it when necessary.
Source Code and Output Print:
import java.util.*;
System.out.println("Enter elements:");
for (int i = 0; i < n; i++) {
arr[i] = sc.nextInt();
}
Conclusion: Successfully implemented a dynamic array and found the smallest and
largest values.
References: Java Docs, BCA 2nd Semester Lab Manual
Program 2: Program to find GCD using recursive function
Objective: To find the Greatest Common Divisor (GCD) of two numbers using a recursive
function.
Theory: Recursion is a process in which a function calls itself. GCD of two numbers can
be found using Euclid's algorithm, which is efficiently implemented using recursion.
Source Code and Output Print: