Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

Lab No.

11
Arrays Application-I

Object Oriented Programming using JAVA Lab Manual – Page 38|193


Lab No. 6: Arrays Application-I

Objective:
To implements the concept of one dimensional Array.

Scope:
Arrays are special data types that let us store specified number of variables from the same type using one
variable name. Arrays are an indexed data type, which means they are storing different elements discrim-
inating between them using unique index for each one. Declaring and using an array in Java is similar to
declaration of any variable; you have to specify data type and name, in addition to this, you have also to
specify the length of the array before using it.

Example 1: This program is used to calculate the sum of array values.

Object Oriented Programming using JAVA Lab Manual – Page 39|193


Example 2: This program demonstrates how to reverse the array values.

Object Oriented Programming using JAVA Lab Manual – Page 40|193


Example 3: This program demonstrates how to find Maximum and minimum value in arrays.

Object Oriented Programming using JAVA Lab Manual – Page 41|193


Exercises

Exercise 1:

Write a program using arrays to solve the problem. The problem is to read 10 numbers, get the average of
these numbers, and find the number of the items greater than the average.

Exercise 2:

Count the occurrences of each letter in the array. To do so, create an array, say counts, of 26 int values,
each of which counts the occurrences of a letter. That is counts[0] counts the number of a’s, counts[1]
counts the number of b’s, and so on.

Exercise 3:

Write a program that reads 10 numbers in an array, write a method which will return the sort array.

Homework:

1. (Eliminate duplicates) Write a method that returns a new array by eliminating the duplicate values in
the array. Write a JAVA program that reads in at least ten integers, invokes the method, and displays
the results.

Object Oriented Programming using JAVA Lab Manual – Page 42|193

You might also like