Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- I'm trying program to calculate sequence of factorial numbers.
- ex) if n = 5
- 5! + 4! + 3! + 2! + 1!
- import java.util.Scanner;
- public class practices {
- public static void main(String[] args) {
- Scanner input = new Scanner(System.in);
- System.out.println("Give n: ");
- int n = input.nextInt();
- double sum = 0.0;
- int j = n-1;
- do {
- double fact = n;
- for (int i = (n - 1); i > 0; i--) {
- fact *= i;
- }
- sum += fact;
- j--;
- } while (j > 0);
- System.out.println(sum);
- }
- }
- This is what I have so far... Do you know what's wrong with the code?
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement