+ 4

What is code for factorial in java

coding used is loop

6th Mar 2018, 5:39 PM
Aryan Agarwal
Aryan Agarwal - avatar
5 Answers
+ 4
Please go through this code...That will help you. https://code.sololearn.com/c7tgNvlD6T12/?ref=app
6th Mar 2018, 5:49 PM
Pravin Pandey
Pravin Pandey - avatar
+ 2
JavaScript let num = Number(prompt("Enter a number")); let fact = 1; while(num) { fact*=num; num-=1; }alert(fact);
6th Mar 2018, 6:02 PM
RZK 022
RZK 022 - avatar
7th Mar 2018, 4:20 AM
Abhimanyu Kumar
+ 2
import java.util.Scanner; class Factorial { public static void main(String[] args){ int no, factorial=1; Scanner s=new Scanner(System.in); System.out.println("Enter Number :"); no=s.nextInt(); for(int i=1; i<=no; i++) { factorial=factorial*i; } System.out.println("Factorial is :" +factorial); } }
7th Mar 2018, 4:21 AM
Abhimanyu Kumar
+ 2
import java.util.Scanner; class fact { public static void main(String args()) { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int factorial=1; for(int i=1;i<=n;i++) { factorial=factorial*i; } System.out.println("Factorial of"+n+"is"+factorial); } }
10th Mar 2018, 5:29 AM
VamsiKrishna
VamsiKrishna - avatar