Friends please help me out to solve this problem .....
1 import java.io.*;
2 class Factorial
3 {
4 public static void main(String args[]) throws IOException
5 {
6 System.out.println("Enter a value=");
7 DataInputStream a =new DataInputStream(System.in);
8 int b=Integer.parseInt(a.readLine());
9 int result=frac(b);
10 System.out.println("The factorial of "+b+" is " +result);
11 }
12 public static int frac(int a)
13 {
14 int j=a;
15 for(int i=1;i<j;i++)
16 {
17 a=a*(j-i);
18 }
19 return a;
20 }
21 }
Actually the program is perfectly running but ..
Problem is that [B]In LIne no.-15 if i replace j by a , like for(int i=1;i<a;i++) the result was totally different (was showing output as 0) ....
my objective is :- why it has different output thow j and a have same value .... [/B]