Advertisement
illpastethat

Hmm...

Jun 9th, 2011
297
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.54 KB | None | 0 0
  1. I'm trying program to calculate sequence of factorial numbers.
  2. ex) if n = 5
  3. 5! + 4! + 3! + 2! + 1!
  4.  
  5. import java.util.Scanner;
  6. public class practices {
  7. public static void main(String[] args) {
  8. Scanner input = new Scanner(System.in);
  9. System.out.println("Give n: ");
  10. int n = input.nextInt();
  11.  
  12. double sum = 0.0;
  13. int j = n-1;
  14. do {
  15. double fact = n;
  16. for (int i = (n - 1); i > 0; i--) {
  17. fact *= i;
  18. }
  19. sum += fact;
  20. j--;
  21. } while (j > 0);
  22. System.out.println(sum);
  23. }
  24. }
  25.  
  26. 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