Abdul Subhan Lab Report 2
Abdul Subhan Lab Report 2
ABDUL SUBHAN
REG NO:
B21F0110SE008
DEPT:
SE2
DATED:2/3/2024
LAB#2 REPORT
OBJECTIVES:
This aims on practicing of java basics. We practice arrays 2 dimensional
arrays and constructors and destructors. We will do some tasks to recall the basics of java.
TASKS:
TASK1: Searching for a Specific Element
CODE:
class Main {
// Function to implement
// search operation
static int findElement(int arr[], int n, int key)
{
for (int i = 0; i < n; i++)
if (arr[i] == key)
return i;
// If the key is not found
return -1;
}
// Driver's Code
public static void main(String args[])
{
int arr[] = { 12, 34, 10, 6, 40 };
int n = arr.length;
CODE:
import java.util.*;
class Array {
public static void main(String[] args) {
int a[]={1,423,6,46,34,23,13,53,4};
//Implemented inbuilt function to sort array
Arrays.sort(a);
// after sorting the value at 0th position will minimum and
//nth position will be maximum
System.out.println("min= "+a[0]+" max= "+a[a.length-1]);
}
}
OUTPUT: