write the statement to print the sum of last two elements in the array of 10 elements
int a[]= new int [10];
print sum of last two elements
Answers
Answered by
1
Answer:
import java.util.*:
class Main{
int a[]=new a[100];
System.out.println("Enter the length of array:");
n=nextInt();
Scanner sc= new Scanner();
for(int i=0;i<n;i++)
{
a[i]=sc.nextInt();
}
int sum=a[n-1]+a[n-2];
System.out.println(sum);
}
Explanation:
Here, we can take n number of array length limited to 100, this shall print the sum of last two elements.
I hope this helps you.
Please mark as brainliest accordingly.
Answered by
3
Write the statement to print the sum of last two elements in the array of 10 elements.
int a[]=new int[10];
index value of last two elements is 9 and 8.
So,
int Sum=a[8]+a[9];
System.out.println(sum);
Similar questions