Full width home advertisement

Java

Tech News

Ad

  1. package clgPracticals;
  2.  
  3. import java.util.Scanner;
  4.  
  5. class Pr3 {
  6. public static void main(String[] args) {
  7. Scanner a = new Scanner(System.in); // creating object of Scanner
  8. int ans = 1, n;
  9. System.out.print("Enter number ");
  10. n = a.nextInt(); // Will assign numerical value to n
  11. a.close();
  12.  
  13. // Main Logic
  14. for (int i = n; i > 0; i--) {
  15. ans = ans * i;
  16. }
  17. System.out.println("the factorial of " + n + " is " + ans);
  18. }
  19. }
  20.  

No comments:

Post a Comment

Bottom Ad [Post Page]