How to calculate Factorial of a number using for loop in Java

How to calculate Factorial of a number using for loop in Java

Dinesh Varyani

11 лет назад

31,539 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

Smart Programming
Smart Programming - 08.04.2018 05:43

helpful tutorial, easy to understand 👍👍

Ответить
Gavin S
Gavin S - 26.10.2017 01:09

oh i found it's good to replace int with double for more numbers

Ответить
Gavin S
Gavin S - 26.10.2017 00:59

how come when i put an integer greater or equal to 21, the factorial is negative? plz help

(it is negative for 21, 22, 24 and some others

Ответить
Pete Logos
Pete Logos - 12.09.2017 13:51

you're awesome! Thanks!

Ответить
Prajna Nayak
Prajna Nayak - 22.12.2016 14:03

class Factorial
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter a Number for factorial:");
n = sc.nextInt();


int number,fact=1;
for(int i=1; i<=number;i++)
{
fact=fact*i;
}
System.out.println("factorial Number is " + fact);
}
}

Ответить
Bruno López
Bruno López - 20.11.2016 23:20

please learn english

Ответить
Dipanshu
Dipanshu - 13.10.2016 17:10

Well explained

Ответить
Dilshad
Dilshad - 28.02.2016 12:47

helped me a lott....thanx

Ответить
Animated Gaming123
Animated Gaming123 - 06.01.2016 01:59

This helped!!!!!!!!!!!

Ответить