forked from cs-dept-ibbul/java2019
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLab5Arithmetic progression.java
More file actions
52 lines (40 loc) · 1.49 KB
/
Copy pathLab5Arithmetic progression.java
File metadata and controls
52 lines (40 loc) · 1.49 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package assignment;
import java.util.Scanner;
/**
*2
* @author
*/
public class ArithmeticProgression {
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
double firstTerm = 0;
double numberOfTerms = 0;
double nthTerm = 0;
double commonDifference = 0;
double sum= 0;
double term = 0;
System.out.print("Enter the value of a (First Term) : ");
firstTerm = input.nextDouble();
System.out.print("Enter the value of d (Common Difference) : ");
commonDifference = input.nextDouble();
System.out.print("Enter the value of n (Number of terms) : ");
numberOfTerms = input.nextDouble();
nthTerm = firstTerm + (numberOfTerms - 1) * commonDifference;
sum = numberOfTerms * (2 * firstTerm + (numberOfTerms - 1) * commonDifference)/2;
System.out.println("");
System.out.println("The Arithmetic Progression is as follows :");
for(int i = 0; i < numberOfTerms; i++){
term = firstTerm + i * commonDifference;
System.out.print(term+" + ");
}
System.out.println("...");
System.out.println("The nthTerm of the series : " + nthTerm);
System.out.println("The Sum of n terms of series : " + sum);
}
}