-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharraysum.java
More file actions
53 lines (43 loc) · 1.2 KB
/
arraysum.java
File metadata and controls
53 lines (43 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import java.util.Scanner;
public class arraysum {
public static void main(String[] args) {
// TODO Auto-generated method stub
int n,i,total = 0;
Scanner s= new Scanner(System.in);
//first array
System.out.print("Enter the number of elements");
int a= s.nextInt();
int array[]= new int[a];
System.out.println("the following elements are:");
for(i=0;i<a;i++)
{
array[i]= s.nextInt();
}
// second array
System.out.print("Enter the number of elements for second array");
int b= s.nextInt();
int array1[]= new int[b];
System.out.println("the following elements are:");
for(i=0;i<b;i++)
{
array1[i]= s.nextInt();
}
int sum=0;
for(i=0;i<a;i++)
{
sum= sum+array[i];
}
System.out.println("Sum of first array" +sum);
int sum1=0;
for(i=0;i<b;i++)
{
sum1= sum1+array1[i];
}
System.out.println("sum of second array" +sum1);
for(i=0;i<a;i++)
{
total= sum + sum1;
}
System.out.println("the sum of both the array:" +total);
}
}