-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTermsOfAP.java
More file actions
39 lines (37 loc) · 851 Bytes
/
TermsOfAP.java
File metadata and controls
39 lines (37 loc) · 851 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
// Problem
// Result
// Terms of AP
// Send Feedback
// Write a program to print first x terms of the series 3N + 2 which are not multiples of 4.
// Input format :
// Integer x
// Output format :
// Terms of series (separated by space)
// Constraints :
// 1 <= x <= 1,000
// Sample Input 1 :
// 10
// Sample Output 1 :
// 5 11 14 17 23 26 29 35 38 41
// Sample Input 2 :
// 4
// Sample Output 2 :
// 5 11 14 17
import java.util.Scanner;
public class TermsOfAP {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int n = s.nextInt();
int count = 1;
int i=1;
while (count <= n) {
int AP = 3 * i + 2;
if (AP % 4 != 0) {
System.out.print(AP + " ");
count++;
}
i++;
}
s.close();
}
}