Arithmetic Progression - Nth Term JAVA EASY PART-005
Arithmetic Progression - Nth Term
The first three terms in an arithmetic progression are passed as input. A positive integer value N (where N > 3) is also passed as the input. The program must print Nth term in the arithmetic progression.
PROGRAM IN JAVA
***********************************************************************************
import java.util.*;
public class Hello {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
String s=sc.nextLine();
String[] s1=s.split(" ");
int a=Integer.parseInt(s1[0]);
int b=Integer.parseInt(s1[1]);
int c=Integer.parseInt(s1[2]);
int d=sc.nextInt();
System.out.print(a+(d-1)*Math.abs(b-c));
}
}
**********************************************************************************
Comments
Post a Comment