Posts

Showing posts with the label geometric

mathajax

Arithmetic and Geometric Sequence

Image
Arithmetic Sequence The program generates arithmetic sequence of K items.  on executing the program, user asked to the following input values  a (start value) , d (common difference) and K (number of elements in the sequence) to generate the sequence.   a - starting value  d - common difference import java.util.Scanner; public class ArithSequence { public static void main(String[] args) { // TODO Auto-generated method stub System.out.println( "Generate Arithmetic Sequence n" ); Scanner sc = new Scanner(System.in); System.out.println( "starting value for a " ); int a = sc.nextInt(); System.out.println( "Enter common deference for d " ); int d = sc.nextInt(); System.out.println( "Enter K items in sequence" ); int K = sc.nextInt(); sc.close(); System.out.println( "nSequence " ); int s=0; for ( int n=0; n < K ; n++ ) { s = n*d + a; System.out.pr int ( ...