Previously we have discussed the Program for
import java.util.Scanner;
public class Factorial {
public static void main(String[] args) {
System.out.print("Enter Number For Factorial : ");
Scanner sc=new Scanner(System.in);
int num = sc.nextInt();
int out =1;
for(int j=1;j<=num;j++){
out = out * j;
}
System.out.println("OUTPUT : "+out);
}
}
Program Output :-
Enter Number For Factorial :
5
OUTPUT : 120
Java program to Check Year Is Leap Year or Not ?
Below Program is used to calculate Factorial of any Number . Factorial is denoted by n!, is the product of all positive integers less than or equal to n. For example, 5 ! = 5 × 4 × 3 × 2 × 1 = 120.
The above example is implemented through program.
import java.util.Scanner;
public class Factorial {
public static void main(String[] args) {
System.out.print("Enter Number For Factorial : ");
Scanner sc=new Scanner(System.in);
int num = sc.nextInt();
int out =1;
for(int j=1;j<=num;j++){
out = out * j;
}
System.out.println("OUTPUT : "+out);
}
}
Program Output :-
Enter Number For Factorial :
5
OUTPUT : 120
Java I/O Tutorial
No comments:
Post a Comment