Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Instructions An arithmetic progression is a sequence of numbers in which the dis

ID: 3757523 • Letter: I

Question

Instructions An arithmetic progression is a sequence of numbers in which the distance (or difference) between any two successive numbers is the same. This in the sequence 1, 3, 5, 7, ..., the distance is 2 while in the sequence 6, 12, 18, 24, . .., the distance is 6. Given the positive integer distance and the non-negative integer n, create a list consisting of the arithmetic progression between land including) 1 and n with a distance of distance. For example, if distance is 2 and n is 8, the list would be [1, 3, 5, 7] Associate the list with the variable arith prog.

Explanation / Answer

/* package whatever; // don't place package name! */

import java.util.*;

import java.lang.*;

import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */

class Ideone

{

public static void main (String[] args) throws java.lang.Exception

{

// your code goes here

int i, d, n;

i=n=0;

Scanner sc = new Scanner(System.in);

System.out.print("Enter a positive integer distance: ");

d=sc.nextInt();

System.out.println();

System.out.println("Enter the value of n(non-negative value): ");

n=sc.nextInt();

int arith_prog[] = new int[n];

for(i = 0; i < n; i++)

{

arith_prog[i] = 0;

}

for(i = 0; i < n / d; i++)

{

arith_prog[i] = 1 + d * i;

}

System.out.println("Created List:- ");

System.out.print("[");

for(i = 0; i < arith_prog.length; i++)

{

if(arith_prog[i] > 0)

{

if(i == n/d - 1)

{

System.out.print(+arith_prog[i]);

}

else

{

System.out.print(+arith_prog[i]+", ");

}

}

}

System.out.print("]");

}

}