Thursday, February 29, 2024

Java Program to calculate Factorial of a given number

import java.util.*;

class Factorial{

public static void main(String args[]){

long fact=1,num;

int i;

Scanner s=new Scanner(System.in);

System.out.println("Enter number");

num=s.nextLong();

if(num>0){

for(i=1;i<=num;i++)

fact=fact*i;

System.out.println("Factorial of"+num+"="+fact);

}

else{

System.out.println("wrong number");

}}}

No comments:

Post a Comment

Java program to implement file input stream class to read binary data from image file.

import java.io.FileInputStream; import java.io.IOException; public class ReadImageFile {     public static void main(String[] args) {       ...