Computer Science, asked by naruto1517, 8 months ago

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 June021
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 anindyaadhikari13
3

\star\:\:\:\sf\large\underline\blue{Question:-}

Write the statement to print the sum of last two elements in the array of 10 elements.

int a[]=new int[10];

\star\:\:\:\sf\large\underline\blue{Answer:-}

index value of last two elements is 9 and 8.

So,

int Sum=a[8]+a[9];

System.out.println(sum);

Similar questions