-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path_1_NumberOfPairsInArrayIsEqualToSum.java
More file actions
37 lines (31 loc) · 1.03 KB
/
_1_NumberOfPairsInArrayIsEqualToSum.java
File metadata and controls
37 lines (31 loc) · 1.03 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
package com.ArraysJava;
import java.util.Scanner;
public class _1_NumberOfPairsInArrayIsEqualToSum {
public static void main(String[] args) {
// write your code here
int n;
int sum = 4;
int[] a = new int[6];
Scanner s = new Scanner(System.in);
System.out.println("Enter the number of values in array");
n = s.nextInt();
System.out.println("Please enter the values of the array");
for (int i = 0; i < n; i++) {
a[i] = s.nextInt();
}
System.out.println("The elements of teh array are");
for (int i = 0; i < n; i++) {
System.out.println(a[i]);
}
for (int i = 0; i < n; i++) {
for (int j = 0; j <= i; j++) {
if (a[i] + a[j] == sum) {
System.out.println("The values of i and j are equal to sum");
System.out.println(a[i]);
System.out.println(a[j]);
break;
}
}
}
}
}