Array is used to Grouping the similar datatype
Array size cannot be defined by datatype
Array is index based because we can get the values from array using index only
Array Maximum length is integer maximum storage size it is applicable for all datatype
Array Minimum length is zero
Examples of Array
1. printing the array value without using the looping concept:
Class Arraypractice{
Public static void main(args[])
{
int[] Marks = {90, 100,79, 84, 98};
System.out.println(Marks[0]);
System.out.println(Marks[1]);
System.out.println(Marks[2]);
System.out.println(Marks[3]);
System.out.println(Marks[4]);
}
}
Output:
90
100
79
84
98
2. Printing the array value using the looping statement:
Class Arraypractice{
Public static void main(args[])
{
int[] Marks = {90, 100,79, 84, 98};
System.out.println(Marks[0]);
System.out.println(Marks[1]);
System.out.println(Marks[2]);
System.out.println(Marks[3]);
System.out.println(Marks[4]);
}
}
Why we go for the looping to printing the array value because in above example array index position is only changing and also for higher value above example is too difficult
Program:
Class Arraypractice{
Public static void main(args[])
{
int[] Marks = {90, 100,79, 84, 98};
for (int i = 0; i<Marks.length; i++){
System.out.println(Marks[i]);
}
}
}
Class Arraypractice{
Public static void main(args[])
{
int[] Marks = {90, 100,79, 84, 98};
while (int i < Marks.length ){
System.out.println(Marks[i]);
}
}
}
Output:
90
100
79
84
98
3. printing the array value in reverse:
Class Arraypractice{
Public static void main(args[])
{
int[] Marks = {90, 100,79, 84, 98};
System.out.println(Marks[4]);
System.out.println(Marks[3]);
System.out.println(Marks[2]);
System.out.println(Marks[1]);
System.out.println(Marks[0]);
Output:
98
84
79
100
90
    
Top comments (0)