write a program to store 10 number each in two array and add their sum in 3rd array and display it .
Answers
Answered by
0
Answer:
class SumOfArray{
public static void main(String args[]){
int[] array = {10, 20, 30, 40, 50, 10};
int sum = 0;
//Advanced for loop
for( int num : array) {
sum = sum+num;
}
System.out.println("Sum of array elements is:"+sum);
}
}
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
Math,
3 months ago
Social Sciences,
3 months ago
Science,
3 months ago
Hindi,
6 months ago
Science,
11 months ago
Computer Science,
11 months ago