-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSeriesProblem_3.java
40 lines (35 loc) · 1015 Bytes
/
SeriesProblem_3.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
package javabeginner;
/**
* @author Md. Talal Wasim
* https://github.com/mdtalalwasim
*/
import java.util.Scanner;
public class SeriesProblem_3 {
public static void main(String[] args) {
//2. 2 + 4 + 6 + .... +n;
/*Scanner input = new Scanner(System.in);
int sum=0;
int n;
System.out.print("Enter last number = ");
n = input.nextInt();
for (int i = 2; i <=n; i= i+2) {
System.out.print(i+" ");
sum = sum + i;
}
System.out.println();
System.out.println(sum);
*/
//4. 1 x 2 x 3 x .... xn;
Scanner input = new Scanner(System.in);
int sum=1;
int n;
System.out.print("Enter last number = ");
n = input.nextInt();
for (int i = 1; i <=n; i= i+2) {
System.out.print(i+" ");
sum = sum * i;
}
System.out.println();
System.out.println(sum);
}
}