To get the sum of two numbers in an array:
- Call the array and return a value within it by using the index of the value you want to retrieve
- Add that value to another call to the array (again, with desired index specified)
- Assign that value to the type you require
Keep in mind that when calling an array to access a stored value, use the index (or position) of the value within the array — then add one. We use this formula of indexOfValue + 1 as most languages start indexing arrays at the 0th position (although this is not always true, for example, Fortran indexes its arrays beginning with 1. So ‘integer anArray(50)’ would create an array capable of storing 50 int elements, starting at index 1 and ending at index 50). Another consequence of this structural design within programming languages is that the last value of an array can be accessed using sizeOfArray - 1.
To clarify these concepts, look at this code:
int[] a = {1,23,4,55};
int firstSum = a[1] + a[3]; // performs 23 + 55
int[] b = {2,5,-66,23};
int secondSum = b[2] + b[3]; // performs -66 + 23
int sumOfLastValues = a[a.length - 1] + b[b.length - 1];
A[0] A[1] A[3]
also please follow naming convention by reading this oracle.com/technetwork/java/codeconventions-135099.html also note that when you say array it should be plural withs
exampleint[] students = new int[5];