//Calculate Factorial of a given no
import java.util.Scanner;
public class Factorial {
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter a no:");
int no=sc.nextInt();
if(no<0)
System.out.println("Can not determine");
else if(no==0)
System.out.println("Factorial=1");
else
{
long f=1L;
for(int i=1;i<=no;i++)
f=f*i;
System.out.println("Factorial="+f);
}
}
}
import java.util.Scanner;
public class Factorial {
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter a no:");
int no=sc.nextInt();
if(no<0)
System.out.println("Can not determine");
else if(no==0)
System.out.println("Factorial=1");
else
{
long f=1L;
for(int i=1;i<=no;i++)
f=f*i;
System.out.println("Factorial="+f);
}
}
}
No comments:
Post a Comment