Handling Arrays in Java

At the point when handling components of an array, we frequently utilize either for or foreach in light of the fact that the majority of the components in an array are of the same sort and the extent of the exhibit is known.

Example:

public class Mytestarray {
public static void main(string[] args) {
double[] myarray = {0.5, 1.2, 2.2, 3.4, 4.7};
for (int k = 0; k < myarray.length; k++) {
System.out.println(myarray[k] + ” “);
}
double aggregate = 0;
for (int k = 0; k < myarray.length; k++) {
aggregate += myarray[k];
}
System.out.println(“Aggregate value = ” + aggregate);
double maxval = myarray[0];
for (int k = 1; k < mylist.length; k++) {
if (myarray[i] > maxval)
maxval = myarray[k];}
System.out.println(“Max Value is ” + maxval);
}

This would create the accompanying result:

0.5 1.2 2.2 3.4 4.7
Aggregate = 12.0
Max Value is 4.7


For any query or issue, feel free to discuss on http://discuss.eduguru.in