Advertisement
Stelios_Gakis

Seminar_2/Task_8

Sep 28th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.79 KB | None | 0 0
  1. package Seminar_2;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Task_8 {
  6.  
  7.     private static final Scanner in = new Scanner(System.in);
  8.  
  9.     public static void main(String[] args) {
  10.  
  11.         Task_8 myApp = new Task_8();
  12.  
  13.         System.out.println("Please enter the number you would like to find the factorial of : ");
  14.  
  15.         int numberForCalculation = in.nextInt();
  16.         int finalAnswer = myApp.factorialCalculation(numberForCalculation);
  17.  
  18.         System.out.println("The answer is : " + finalAnswer);
  19.     }
  20.  
  21.     public int factorialCalculation(int numberToBeCalculated) {
  22.         int solution = 1;
  23.         while (numberToBeCalculated > 0) {
  24.             solution = solution * numberToBeCalculated;
  25.             numberToBeCalculated--;
  26.         }
  27.         return solution;
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement