write a menu driven program for arrays which should be able to perform following:
1. Take size of array from user and accordingly input values in the array along with it should be able to display the values too.
2. Able to insert and delete data element at any position entered by the user.
Answers
We need to be able to read each input value twice: once to compute the average (a cumulative sum) and again to count how many were above average. We could read each value into a variable, but we don't know how many days are needed until the program runs, so we don't know how many variables to declare.
We need a way to declare many variables in one step and then be able to store and access their values.
Challenge: Is it possible to solve the above problem using only the techniques from the previous notes without using arrays? How?
Arrays
An array is an object that stores many values of thposition in an array. Like Strings, arrays use zero-based indexing, that is, array indexes start with 0. The following displays the indexes and values in an array with 10 elements of type int.
index 0 1 2 3 4 5 6 7 8 9
value 12 49 -2 26 5 17 -6 84 72 3
Array declaration and creation
The syntax for declaring an array is:
type[ ] variable;
This just declares a variable that can hold an array, but does not create the array itself.
For example, to declare a variable, numbers that can hold an array of integers, we would use:
int[] numbers;