+ 1
Write a program in bluej a to print the series s= 2! + 5! + 8! ..... n !
it is a series program
1 Antwort
+ 1
import java.util.Scanner;
public class Series
{
public static void main( String args[] )
{
Scanner sc = new Scanner(System.in);
//Enter a number
long n = sc.nextLong();
long s = 0;
for(long i = 2 ; i<=n ; i+=3)
{
long f = 1; //Reset the value of f
//Calculate factorial of the new number
for (long x = 1 ; x<=i ; x++)
f *= x ;
s += f ;
}
System.out.println(s);
}
}
You can use BufferedReader instead of Scanner for input.
Hope it helps!!👍☺️
Please up vote...