top of page
  • Writer's pictureSatyam Gupta

Factorial Series in Java (Series #7)

Updated: Feb 27, 2022

Factorial Series in Java

Question : Write a program to print the following series.


S = 2! + (2! + 3!) - (2! + 3! + 5!) + (2! + 3! + 5! + 7!)......... n terms

The above series is very easy to solve

Logic :-


  • First input number of terms

  • The nth term will contain 'n' number of terms (ex- if n = 2, then it will contain 2 terms i.e. (2! + 3!))

  • calculate the nth term by first finding the first 'n' number of prime numbers

  • Now, calculate factorial of each prime number

  • Add the factorials of all the prime numbers

  • Now if the nth term is odd and not the first then it will be a negative term

  • else it will be a positive term

  • Store the result in the variable accordingly

  • Print the result


Note : To understand the program clearly watch this video : https://youtu.be/CRX9zDJYY4U

 

Program to print the Series :-

Checkout Source Code : Click here

Program Video : Watch Now





22 views0 comments

Recent Posts

See All
Post: Blog2_Post
bottom of page