Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class ap{
- public static void main(){
- Scanner sc = new Scanner(System.in);
- System.out.println("1st term");
- int a = sc.nextInt();
- System.out.println("difference term");
- int d = sc.nextInt();
- System.out.println("nth term");
- int n = sc.nextInt();
- prin(a,d,n);
- }
- static void prin(int a, int d, int n){
- System.out.println("nth term:"+ (a+((n-1)*d)));
- System.out.println("sum till nth term:"+ ((n/2)*((2*a)+((n-1)*d)) ));
- for(int i = 1; i<=n;i++ ){
- System.out.print((a+((i-1)*d))+",");
- }
- System.out.println("");
- for(int i = 1; i<=n;i++ ){
- int k = (a+((i-1)*d));
- int l = 1;
- for(int j =1;j<=k;j++){
- l *=j;
- }
- System.out.print(l+",");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment