Define any array How to initialise one dimensional array? explain with suitable examples
Answers
Answered by
1
Answer:
import java.util.Scanner;
class SumDemo{
public static void main(String args[]){
Scanner scanner = new Scanner(System.in);
int[] array = new int[10];
int sum = 0;
System.out.println("Enter the elements:");
for (int i=0; i<10; i++)
{
array[i] = scanner.nextInt();
}
for( int num : array) {
sum = sum+num;
}
System.out.println("Sum of array elements is:"+sum);
}
}
Similar questions
Science,
2 months ago
English,
2 months ago
Hindi,
2 months ago
Social Sciences,
10 months ago
Social Sciences,
10 months ago
English,
10 months ago