0% found this document useful (0 votes)
44 views7 pages

Name: Syeda Khadija Nadeem REG NO: 20-CS-55 Oop-Lab Lab Maunal-8

The document contains code submissions for 5 lab tasks completed by Syeda Khadija Nadeem for their OOP-LAB class. The first task calculates the average of an integer array. The second finds common elements between two arrays. The third sorts both numeric and string arrays. The fourth inserts a new element into an array at a specified index.

Uploaded by

Olde Gamerz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views7 pages

Name: Syeda Khadija Nadeem REG NO: 20-CS-55 Oop-Lab Lab Maunal-8

The document contains code submissions for 5 lab tasks completed by Syeda Khadija Nadeem for their OOP-LAB class. The first task calculates the average of an integer array. The second finds common elements between two arrays. The third sorts both numeric and string arrays. The fourth inserts a new element into an array at a specified index.

Uploaded by

Olde Gamerz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

5/25/2021

Tuesday

NAME: SYEDA KHADIJA NADEEM


REG NO: 20-CS-55
OOP-LAB
LAB MAUNAL-8

SUBMITTED TO: SIR FAHEEM SALEEM


LAB TASK-1
CODE:
public class arrayy {
public static void main(String[] args) {

int[] numbers = new int[]{8, 15, 5, 35, 1, 9, 0};


int sum = 0;
for(int i=0; i < numbers.length ; i++)
sum = sum + numbers[i];
double average = sum / numbers.length;
System.out.println("Average value of the array elements is : " + average);
}
}

LAB TASK-2
CODE:
import java.util.Arrays;
public class common {
public static void main(String[] args)
{
int[] array1 = {2,6,5,4,7,8};
int[] array2 = {8,9,0,4,6,3};

System.out.println("Array1 : "+Arrays.toString(array1));
System.out.println("Array2 : "+Arrays.toString(array2));

for (int i = 0; i < array1.length; i++)


{
for (int j = 0; j < array2.length; j++)
{
if(array1[i] == (array2[j]))
{

System.out.println("Common element is : "+(array1[i]));


}
}
}

}
}
LAB TASK-3
CODE:
import java.util.Arrays;
public class numericstring {
public static void main(String[] args){

int[] my_array1 = {
17, 35, 9, 146, 201,
18, 24, 122, 25,
16, 65, 17, 26};

String[] my_array2 = {
"Sharjeel",
"Khadija",
"Hussain",
"classes",
"random",
"Ali"
};
System.out.println("Original numeric array : "+Arrays.toString(my_array1));
Arrays.sort(my_array1);
System.out.println("Sorted numeric array : "+Arrays.toString(my_array1));

System.out.println("Original string array : "+Arrays.toString(my_array2));


Arrays.sort(my_array2);
System.out.println("Sorted string array : "+Arrays.toString(my_array2));
}
}
LAB TASK-4
CODE:
import java.util.Arrays;
public class insertElement {
public static void main(String[] args) {
int[] my_arr = {300,800,900,500,600,300,200,100,000};
int Index = 2;
int newV = 5;
System.out.println("Original Array : "+Arrays.toString(my_arr));
for(int i=my_arr.length-1; i > Index; i--){
my_arr[i] = my_arr[i-1]; }
my_arr[Index] = newV;
System.out.println("New Array: "+Arrays.toString(my_arr));
}
}
LAB TASK-5
CODE:

You might also like