Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Seminar_2;
- import java.util.Scanner;
- public class Task_8 {
- private static final Scanner in = new Scanner(System.in);
- public static void main(String[] args) {
- Task_8 myApp = new Task_8();
- System.out.println("Please enter the number you would like to find the factorial of : ");
- int numberForCalculation = in.nextInt();
- int finalAnswer = myApp.factorialCalculation(numberForCalculation);
- System.out.println("The answer is : " + finalAnswer);
- }
- public int factorialCalculation(int numberToBeCalculated) {
- int solution = 1;
- while (numberToBeCalculated > 0) {
- solution = solution * numberToBeCalculated;
- numberToBeCalculated--;
- }
- return solution;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement