JAVA APPLICATION - PACKAGE

AIM:
 
   To write a Java program for the implementation of package.

ALGORITHM:
Step 1: Start
Step 2: Define the class testpck
Step 3: Create the object for the package CFact
Step 4: Read the number
Step 5: Define the method fact() in the package CFact
Step 6: Call the method fact()
Step 7: Perform the factorial operation
Step 8: Display the output
Step 9: Stop

SOURCE CODE:

testpck.java
import java.io.*;
import math.Cfact;
class testpck
{

public static void main(String args[])throws IOException
{
Cfact obj=new Cfact();
System.out.println("Enter the number");
DataInputStream in=new DataInputStream(System.in);
int num=Integer.parseInt(in.readLine());
System.out.println("Factorial is"+obj.fact(num));
}
}

math/Cfact.java
package math;
import java.io.*;
public class Cfact
{
double n;
public Cfact()
{
n=1;
}
public double fact(int a)
{
if(a==0||a==1)
n=1;
else
n=a*fact(a-1);
return n;
}
}

OUTPUT:




















RESULT:
          Thus the Java program for the implementation of package was performed and the output was verified.

.
Previous
Next Post »

If you still didn't find what you're looking for, you can search this website below: