Showing posts with label java factorial. Show all posts
Showing posts with label java factorial. Show all posts

Friday, February 2, 2018

Factorial Number in Java


A simple program that will ask the user to give a number and then our program will compute the factorial value of the given number using Java programming language.  

I am currently accepting programming and web development work kindly contact me in the following email address for further details. Thank you.

My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.

My telephone number at home here in Bacolod City, Negros Occidental is (034) 4335675.






Sample Program Output


Program Listing

factorial.java

import java.util.Scanner;

// factorial.java
// Written By Mr. Jake R. Pomperada, MAED-IT
// February 2, 2018   4:24 PM   Friday
// Bacolod City, Negros Occidental Republic of the Philippines
// jakerpomperada@yahoo.com and jakerpomperada@gmail.com

class factorial {
public static void main(String[] args)
      {

      int num1=0, c=0, fact = 1;


        Scanner s = new Scanner(System.in);

        System.out.println();
        System.out.println("=== Factorial Number in Java === ");
        System.out.println();

         System.out.print("Give a Number : ");
         num1 = s.nextInt();

if (num1 < 0) {
     System.out.println("\n");
         System.out.println("Number should be non-negative.");
}
      else
      {
         for (c = 1; c <= num1; c++)
            fact = fact*c;
   }
         System.out.println("\n");
         System.out.println("The factorial value of "+num1+" is = "+fact);
System.out.println("\n");
System.out.println("\t End of Program");
         System.out.println();
}
}