-
Notifications
You must be signed in to change notification settings - Fork 0
/
que5_2.java
45 lines (37 loc) · 1.3 KB
/
que5_2.java
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
import java.util.*;
public class que5_2 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("enter limit N");
int n = sc.nextInt();
System.out.println("enter a1");
int a1 = sc.nextInt();
System.out.println("enter a2");
int a2 = sc.nextInt();
System.out.println("enter n1 and n2 for two APs");
int n1 = sc.nextInt();
int n2 = sc.nextInt();
System.out.println("enter common ratio r1 and r2 for the two APs");
int r1 = sc.nextInt();
int r2 = sc.nextInt();
if (n1 <= n && n2 <= n) {
int flag = 0;
for (int k = 1; k <= n; k++) {
for (int j = 1; j <= n; j++) {
if ((a1 + (k - 1) * r1) == (a2 + (j - 1) * r2)) {
flag++;
}
if (flag != 0) {
System.out.println(flag+"Common elements are present in the both AP");
}
}
}
else {
System.out.println("no common element found");
}
}
else {
System.out.println("Invalid input for commin ratio");
}
}
}