Write a java program (using any of these: if, if-else, while, do-while, for) to print factorial of any given number.
Answers
Answered by
1
//To find the factorial of 10 using do-while statement.
public class factorial
{
public static void main(String args[])
{
int i,f ;i=1;f=1;
do
{
f=f * i ;
i++
}
while(i<=10);
System.out.println("The factorial of 10 = "+f);
}
}
*************************HOPING THAT THIS WILL HELP YOU!!!**********************
public class factorial
{
public static void main(String args[])
{
int i,f ;i=1;f=1;
do
{
f=f * i ;
i++
}
while(i<=10);
System.out.println("The factorial of 10 = "+f);
}
}
*************************HOPING THAT THIS WILL HELP YOU!!!**********************
kooper:
Plz mark it as best!!!............... : )
Answered by
0
import java.io.*;
class fact
{
int fac(int a)
{
if(a=0)
return(1);
else
return(n*fac(n-1));
}
public static void main(String args[])
{
int b;
InputStreamReader read=new InputStreamReader(System.in);
BufferedReader in=new BufferedReader(read) ;
System.out.println("Enter the number");
b=Integer.parseInt(in.readLine());
fact ob=new fact;
ob.fac(b);
}
}
hope i helped u:)
class fact
{
int fac(int a)
{
if(a=0)
return(1);
else
return(n*fac(n-1));
}
public static void main(String args[])
{
int b;
InputStreamReader read=new InputStreamReader(System.in);
BufferedReader in=new BufferedReader(read) ;
System.out.println("Enter the number");
b=Integer.parseInt(in.readLine());
fact ob=new fact;
ob.fac(b);
}
}
hope i helped u:)
Similar questions
Physics,
8 months ago
Social Sciences,
8 months ago
Math,
1 year ago
English,
1 year ago
Chemistry,
1 year ago