Computer Science, asked by malkedinikhitha123, 4 months ago

Define any array How to initialise one dimensional array? explain with suitable examples​

Answers

Answered by lalitnit
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