0% found this document useful (0 votes)
19 views11 pages

Inft231101081 Oop Lab 5

The document discusses arrays in Java. It provides objectives of understanding and manipulating arrays. It asks questions about array size limits, accessing array elements, finding maximum and minimum values, removing duplicate values, and calculating the transpose of a 2x3 matrix.

Uploaded by

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

Inft231101081 Oop Lab 5

The document discusses arrays in Java. It provides objectives of understanding and manipulating arrays. It asks questions about array size limits, accessing array elements, finding maximum and minimum values, removing duplicate values, and calculating the transpose of a 2x3 matrix.

Uploaded by

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

JAVA ARRAYS

Lab-05

Submitted by: Abdul Samad.


Submitted to: Ms Kiran Yaqoob.
Roll no: Inft231101081.

LAB 05 Arrays in Java

Lab Objectives:
1. Understanding arrays and their implementation in java
2. Manipulating arrays in java

Software Required:
JDK & Notepad/ Textpad

ARRAYS
An array is a container object that holds a fixed number of values of a single type. The length of
an array is established when the array is created.

Question 1:
Describe and explain what happens when you try to compile a program HugeArray.java with the
following statement:

int n = 1000;
int[] a = new int[n*n*n*n];

Question 2:

Set up an array to hold the following values, and in this order: 23, 6, 47, 35, 2, 14. Write a program
to get the average of all 6 numbers. Use foreach loop.
Question 3:
Using the above values in Question 5, have your program print out the highest and lowest

numbers in the array. Use foreach loop.

Question 4:
Use a one-dimensional array to solve the following problem: Write a program that inputs 5

numbers, each of which is between 10 and 100, inclusive. As each number is read, display it only
if it is not a duplicate of a number already read. Provide for the “worst case,” in which all 5 numbers
are different. Use the smallest possible array to solve this
problem.
->

Question 5:
Write a code which calculates transpose of 2x3 matrix.

QUESTIONS

Please Fill the blank space with respective answers to following questions:
Question 1: What will be the last element of an array whose size is 24?
Question 2: What will be the output of the following program?
public class DemoOnLong
{ public static void main(String[]
args)
{
long[][] input = new long[3][];
input[0] = new long[2]; input[1]
= new long[3]; input[2] = new
long[5]; input[0][1] = 12L;
System.out.println(input[0][1]);
}

Question 3: Write a program to multiply every array element with 3.

class MultiplyEveryArrayElement
{ public static void main(String s[])
{
int[] input = { 3, 5, 6, 7 };
int[] output = multiplyEveryElement(input);
System.out.print("Result of multiplying every element by 3 is : ");
for(int outputElement : output)
{
System.out.print(outputElement + ", ");
}
}

public static int[] multiplyEveryElement(int[] input)


{ int[] result = null;
//Write code of this part in the box below to multiply every element with 3 and assign it to
result.
return result;
}
}

You might also like