Factorial.java:19: 'void' type not allowed here
return n*fact(n-1);
^
1 error
Press any key to continue . . .
That is the error message that I am getting. It's the first time I've ever seen anything like it!
The code is right below.
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
class Factorial {
public static void fact(int x) {
int f=1;
for (int i=1;i<x;i++){
f*=i;
}
System.out.println(f);
}
public static int factr(int n) {
if (n==1)
{
return n;
}
else
{
return n*fact(n-1);
}
}
public static void main(String[] args)throws IOException {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter a Number : ");
int input=Integer.parseInt(br.readLine());
fact(input);
int output=factr(input);
}
}

New Topic/Question
Reply




MultiQuote








|