Inft231101081 Oop Lab 5
Inft231101081 Oop Lab 5
Lab-05
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
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]);
}
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 + ", ");
}
}