In this section, you'll learn what arrays are, and how to declare them.
Introduction:
So far, you have been working with variables that hold only one value. The integer variables you have set up have held only one number, and the string variables just one long string of text.
int number0 = 0,number1= 1,number2= 2,..........................;
String one = "One",two = "Two",.....................;
let's assume we have hundred's of int variables and we have been declared hundred's of variables in our program.If we think of readability and maintenance of code then how hard it will be ,because of this sun people introduced array concept.
Instead of declaring individual variables, such as number0, number1, ..., and number99, you declare one array variable such as numbers and use numbers[0], numbers[1], and ..., numbers[99] to represent individual variables.
Example:
int number0 = 0,number1= 1,number2= 2,........int nightyNine = 99;
or
int[] numbers = new int[100];
numbers[0]=1;
numbers[1]=2;
numbers[99]=100;
An array is a flexible structure for storing a sequence of values all of the same type.
Introduction:
So far, you have been working with variables that hold only one value. The integer variables you have set up have held only one number, and the string variables just one long string of text.
int number0 = 0,number1= 1,number2= 2,..........................;
String one = "One",two = "Two",.....................;
let's assume we have hundred's of int variables and we have been declared hundred's of variables in our program.If we think of readability and maintenance of code then how hard it will be ,because of this sun people introduced array concept.
Instead of declaring individual variables, such as number0, number1, ..., and number99, you declare one array variable such as numbers and use numbers[0], numbers[1], and ..., numbers[99] to represent individual variables.
Example:
int number0 = 0,number1= 1,number2= 2,........int nightyNine = 99;
or
int[] numbers = new int[100];
numbers[0]=1;
numbers[1]=2;
numbers[99]=100;
An array is a flexible structure for storing a sequence of values all of the same type.