Modal Box

Input Output in java

In java, all input classes are imported in package java.io

Program to take input as runtime and calculate the factorial :

import java.io.*
class Factorial
{
public static void main(String args[])
{
try
{
InputStreamReader in=new InputStreamReader(System.in);
BufferedReader br= new BufferedReader(in);
System.out.println("enter the number ");
int n=Integer.parseInt(br.readLine());
int f=1;

while(n>0)
{
f=f*n;
n--;
}
System.out.println("the factorial is"+f);
}
catch(Exception ex){
System.out.println("the exception is"+ex);
}
}
}

Video/ C Introduction

Watch video in full size
Wordpress Social Share Plugin powered by Ultimatelysocial