-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuestion1.java
More file actions
36 lines (30 loc) · 849 Bytes
/
Question1.java
File metadata and controls
36 lines (30 loc) · 849 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
import java.util.*;
public class Question1{
public static void main(String args[])
{
Scanner input = new Scanner(System.in);
System.out.println("Enter size of array ->");
int n=input.nextInt();
System.out.println("Enter elements of Array ->");
int a[]=new int[n];
for(int i=0;i<n;i++)
{
a[i] = input.nextInt();
}
System.out.println("Enter Sum ->");
int temp=input.nextInt();
for(int i=0;i<n-1;i++)
{
int sum=a[i];
for(int j=i+1;j<n;j++)
{
sum=sum+a[j];
if(sum==temp)
{
System.out.println("Starting index : "+i);
System.out.println("Endeing index : "+j);
}
}
}
}
}