Series (the liens)

Code


import java.util.Scanner;

public class AmirSequanceCal
    {
        public static void main( String[] args )
        {
            Scanner keyboard = new Scanner(System.in);
            System.out.println();
            
            int n,f, d, s, t;
            do {
                System.out.println("What is your N?");
                n = keyboard.nextInt();
                System.out.println();
                System.out.println("What is your first number?");
                f = keyboard.nextInt();
                System.out.println();
                System.out.println("What is your difference?");
                d = keyboard.nextInt();
                
                System.out.println();
                System.out.println("Press 1 for Arithmatic or press 2 for Geo.");
                s = keyboard.nextInt();
                
                if ( s == 1){
                    
            
            
            for ( t=1; t <= n; t++ )
            {
                System.out.println();
                System.out.print( " a"+ t + ": "  +f+ "+(" + t + "-1)*" +d+ ") = " + (f+((t-1)*d)));
                }
                    
                }
                else
                
            for ( t=1; t <= n; t++ )
            {
                System.out.println();
                System.out.print( " a"+ t + ": "  +f+ "*(" + d + ")^" + t+ "-1 = " + f*(Math.pow(d,t-1)));
                }
            
            
            System.out.println();
        }while (n != 0);
        }
}




    

Picture(s) of the output

Assignment 7

Back to Homepage