Mrgentledolphin

calcolo del fattoriale/ factorial

Nov 19th, 2016
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.39 KB | None | 0 0
  1. package crediti;
  2. import java.util.*;
  3. public class Fattoriale {
  4.  
  5.     public static void main(String[] args) {
  6.         // TODO Auto-generated method stub
  7.  
  8.         int n;
  9.         float f = 1;
  10.        
  11.         Scanner input;
  12.         input= new Scanner(System.in);
  13.         System.out.println("input n");
  14.         n=input.nextInt();
  15.        
  16.         f=n;
  17.         while(n>1){
  18.             n=n-1;
  19.             f=f*n;
  20.         }
  21.            
  22.         System.out.println("fattoriale: "+f);
  23.        
  24.     }
  25.  
  26. }
Advertisement
Add Comment
Please, Sign In to add comment