Computer Applications
Write a Java program to input a number. Calculate and display the factorial of each digit.
Sample Input: 365
Sample Output:
Factorial of 5 = 120
Factorial of 6 = 720
Factorial of 3 = 6
Java
Java Iterative Stmts
74 Likes
Answer
import java.util.Scanner;
public class KboatDigitFactorial
{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.print("Enter number: ");
int n = in.nextInt();
while (n != 0) {
int d = n % 10;
n /= 10;
int f = 1;
for (int i = 1; i <= d; i++) {
f *= i;
}
System.out.println("Factorial of " + d + " = " + f);
}
}
}Output

Answered By
26 Likes
Related Questions
Write a program in Java to find the Fibonacci series within a range entered by the user.
Sample Input:
Enter the minimum value: 10
Enter the maximum value: 20Sample Output:
13Define a class to accept a number from user and check if it is an EvenPal number or not.
(The number is said to be EvenPal number when number is palindrome number (a number is palindrome if it is equal to its reverse) and sum of its digits is an even number.)
Example: 121 – is a palindrome number
Sum of the digits – 1+2+1 = 4 which is an even number