Write a Java-program to print Factorial Number program using parametarized constructor with return type with parametarized method

Write a Java-program to print Factorial Number program using parametarized constructor with return type with parametarized method

Program
import java.util.*;
class Factorial
{
    int n;
    Factorial(int m)
    {
        n=m;
    }
    int fact(int x,int f)
    {
        
        for(x=1;x<=n;x++)
        {
            f=f*x;
        }
        return(f);
    }
}
public class Main
{
    public static void main(String args[])
    {
        int n;
        Scanner s=new Scanner(System.in);
        System.out.println("Enter n value : ");
        n=s.nextInt();	
        Factorial ff=new Factorial(n);
        int p=ff.fact(1,1);
        System.out.println(p);
    }
}


Output:

Enter n value : 5
120

Constructors In Java



More Questions


128 . Write a Java-program to print Factorial Number program using parametarized constructor with return type with no parametarized method
129 . Write a Java-program to print Factorial Number program using parametarized constructor with return type with parametarized method
130 . Write a Java-program using this.(dot)
131 . Write a Java-program with out using this()
132 . Write a Java-program with using this()
133 . Write a Java program to print student details using single inhiritance concept
134 . Write a Java program to print student details using multilevel inhiritance concept
135 . Write a Java program to print student and faculty details using hirarchy inhiritance concept
136 . Write a Java program with out using abstract keyword
137 . Write a Java program with using abstract keyword
138 . Abstract Practice Program 1