+1 vote
in JAVA by

Write a program to calculate the factorial of a number in java.

1 Answer

0 votes
by

Write a program to calculate the factorial of a number in java.

import java.util.Scanner; 

public class star { 

     public static void main(String[] args) { 

         Scanner sc=new Scanner(System.in); 

         int fact=1; 

         int n=sc.nextInt(); 

         for (int i=1;i<=n;i++) 

         fact=fact*i; 

         System.out.println(fact); 

        } 

🔗Reference: stackoverflow.com

🔗Source: Java Interview Questions and Answers

Related questions

0 votes
asked Nov 25, 2020 in JAVA by SakshiSharma
+1 vote
asked Oct 24, 2020 in JAVA by sharadyadav1986
...