Factorial Program Using Java With I/O Streams

Introduction

In this blog, I will explain about the Factorial program, using Java I/O stream. It is very simple in Java programming. The output will be displayed in the Run module.

Software Requirement

JDK1.3.

Simple program

  1. import java.io.*;  
  2. class da  
  3.  {  
  4.   public static void main(String arg[]) throws IOException  
  5.    {  
  6.     DataInputStream d = new DataInputStream(System.in);  
  7.     int i,n,f;  
  8.     String s;  
  9.     f=1;  
  10.     System.out.print("enter the number : ");  
  11.    s = d.readLine();  
  12.     n = Integer.parseInt(s);   
  13.      for(i=1;i<=n;i++)  
  14.       {   
  15.         f = f * i;  
  16.       }  
  17.     System.out.println("\n"+"factorial of given number "+n+" is : " +f);  
  18.    }  
  19.  }          
Explanation

In this blog, I will explain about the Factorial program, using Java I/O stream. The output will be displayed in the Run module.

Output