/* Write a java program, where you accept an intger from the user in the main() method. Check if the number is greater than 0. If not, print an error message. If it's greater than 0, pass it as an argument to the method called "fact" In the "fact" method, calculate the factorial of the number and return it. Print the result in main. cd The factorial of a non-negative integer n, denoted by n!, is the product of all positive integers less than or equal to n. n! = 1x2x3x4 .... (n-1)xn 5! = 1x2x3x4x5 = 120 Factorials can grow very fast. Ints may be too small. */ import java.util.Scanner; class Quiz10_21 { static long fact (int num) { long result = 1; // ints are too small. We use longs instead. for(int i=1;i<=num;i++) // Count from 1 to the number and multiply up. result = result * i; return result; } public static void main(String [] args) { Scanner in = new Scanner (System.in); System.out.println("Enter a number : "); int number = in.nextInt(); if(number<=0) // If number is not positive, print error message. System.out.println("The number you enteres was not positive."); else System.out.println("The factorial is " + fact(number)); } }