write a program in function
Attachments:
Answers
Answered by
21
Java is a machine independent language which can work on any platform. Its an object oriented programming which stress on object rather than data.
◼Functions are the part of java programming in modules used simultaneously ay different instances to perform specific task.
◼m! and n!means the product of all numbers till m and n .
◼Then forming java expression.
import java . util . *;
class factor
{
public int fact(int n)
{
int m , S i ,j ,a=1 ,b=1 ,c=1,k;
Scanner Sc=new Scanner(System . in);
System . out . println("Enter any number");
m=Sc . nextInt();
for(i= 1;i<=m ;i++)
{
a= a*i;
}
for(j=1;j<=n;j++)
{
b=b*j;
}
for(k=1;k<=(n-m);k++)
{
c=c*k;
}
S=a/b*c;
return(S);
}
public static void main(String args[])
{
int p ,r;
Scanner Sc=new Scanner(System . in);
System . out . println("Enter any number");
r=Sc . nextInt();
factor obj=new factor(System . in);
p=obj . fact(r);
System . out . println("S"+S);
}
}
Enter any number
2
Enter any number
2
So,
S will be 2.
Anonymous:
Supeb!!!
Similar questions
World Languages,
6 months ago
Hindi,
6 months ago
Social Sciences,
6 months ago
Economy,
11 months ago
English,
11 months ago
Science,
1 year ago
Art,
1 year ago