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
English,
2 months ago
Biology,
2 months ago
Math,
2 months ago
Social Sciences,
11 months ago
Social Sciences,
11 months ago
English,
11 months ago