Advertisement
Thanhsy

De Qui

Aug 31st, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.95 KB | None | 0 0
  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5. package D31_8;
  6.  
  7. import java.util.Scanner;
  8.  
  9. /**
  10.  *
  11.  * @author Administrator
  12.  */
  13. public class De_Qui {
  14.    
  15.     public static void main(String[] args) {
  16.         Scanner input = new Scanner(System.in);
  17.         System.out.print("Nhap n : ");
  18.         int n = input.nextInt();
  19.        
  20.         System.out.println("Ket qua :  " + De_Qui.Giai_Thua(n));
  21.        
  22.         De_Qui dequi = new De_Qui();
  23.         System.out.println("Ket qua :  " + dequi.Giai_Thua_nonStatic(n));
  24.        
  25.        
  26.     }
  27.    
  28.     public static long Giai_Thua(int n) {
  29.         if (n == 0) {
  30.             return 1;
  31.         } else {
  32.             return n * Giai_Thua(n - 1);
  33.         }
  34.     }
  35.    
  36.     public long Giai_Thua_nonStatic(int n) {
  37.         if (n == 0) {
  38.             return 1;
  39.         } else {
  40.             return n * Giai_Thua_nonStatic(n - 1);
  41.         }
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement