Advertisement
Svetlana_Ovsjanikova

java - factorial

Sep 21st, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package day2_factorial;
  7.  
  8. import java.util.Scanner;
  9.  
  10. /**
  11. *
  12. * @author sao_7
  13. */
  14. public class Day2_factorial {
  15.  
  16. /**
  17. * @param args the command line arguments
  18. */
  19. public static void main(String[] args) {
  20. Scanner sc = new Scanner(System.in);
  21. System.out.println("Ievadiet skaitli!");
  22. long number = sc.nextInt();
  23.  
  24. //for cikls, kas aprekina faktoriali
  25. int fact = 1;
  26.  
  27. for(int i = 1; i<=number; i++){
  28. fact = fact * i;
  29. }
  30. System.out.println("Faktorialis ir " + fact);
  31. }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement