-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtwosum.java
More file actions
32 lines (31 loc) · 921 Bytes
/
Copy pathtwosum.java
File metadata and controls
32 lines (31 loc) · 921 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
package array;
import java.util.Scanner;
public class twosum {
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
int n,k,count=0;
System.out.println("enter number of elements in array : ");
n=s.nextInt();
int ar[]=new int[n];
for(int i=0;i<n;i++)
{
System.out.println("enter element : "+i);
ar[i]=s.nextInt();
}
System.out.println("enter sum to be found : ");
k=s.nextInt();
for(int i=0;i<n;i++)
{
for(int j=i+1;j<n;j++)
{
int f=ar[i];
if(f+ar[j]==k)
{
System.out.println("the elements are: "+f+"and"+ar[j]);
count++;
}
}
}
System.out.println("total possibilities are "+count);
}
}