In: Computer Science
import java.util.Scanner;
class Factorial {
public static int calc_factorial(int f) {
int myint= 1;
// put code here
return myint;
}
public int getInt() {
int f = 0;
// put code here
return f;
}
}
public class Assignment06 {
public static void main(String args[]){
System.out.println("Assignmemnt 06 Written by Matt Weisfeld");
int myInt = 0;
// create a Factorial object
Factorial factorial = new Factorial();
// get a number from the console
myInt = factorial.getInt();
System.out.println("Factorial of " + myInt + " is: " +
// calculate the factorial of the number
factorial.calc_factorial(myInt));
}
}
Code:
import java.util.Scanner;
class Factorial {
public static int calc_factorial(int f) {
int myint= 1;
// put code here
if(f>1)
{
for(int i=1;i<=f;i++)
{
/*This loop executes fot i=1 to f*/
myint*=i;
/*Here we multiply every number untill f*/
}
}
return myint;
/*Here we return the factorial*/
}
public int getInt() {
int f = 0;
// put code here
Scanner scnr=new Scanner(System.in);
/*Scanner object is created*/
System.out.print("Enter a number to find its factorial: ");
f=scnr.nextInt();
/*Reading the number form the user*/
return f;
}
}
public class Assignment06 {
public static void main(String args[]){
System.out.println("Assignmemnt 06 Written by Matt
Weisfeld");
int myInt = 0;
/* create a Factorial object*/
Factorial factorial = new Factorial();
/* get a number from the console*/
myInt = factorial.getInt();
System.out.println("Factorial of " + myInt + " is: " +
/* calculate the factorial of the number*/
factorial.calc_factorial(myInt));
}
}
Output:

Indentation :

