- Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patharraySum.java
More file actions
Latest commit
40 lines (40 loc) · 573 Bytes
/
Copy patharraySum.java
File metadata and controls
40 lines (40 loc) · 573 Bytes
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
importjava.util.Scanner;
classarraySum
{
publicstaticvoidmain(Stringargs[])
{
inti,a=0,b=0,sum=0;
Scannersc = newScanner(System.in);
intn = sc.nextInt();
int[] arr = newint[n];
for(i=0;i<n;i++)
{
arr[i] = sc.nextInt();
}
for(i=0;i<n;i++)
{
if(arr[i]==6)
a=i;
if(arr[i]==7)
b=i;
}
if(a<b)
{
for(i=0;i<n;i++)
{
if(i>=a && i<=b)
continue;
else
sum+=arr[i];
}
}
else
{
for(i=0;i<n;i++)
{
sum+=arr[i];
}
}
System.out.println(sum);
}
}