I dont know what's wrong
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
int input = Integer.parseInt(reader.readLine());
reader.close();
System.out.println(factorial(input));
}
public static String factorial(int n) {
//write your code here
String s = "";
if (n <0)
s = "0! = 1";
else if(n == 0)
s = "1";
else {
int factorial = 1;
for (int i = 1; i <= n; i++) {
factorial = factorial * i;
}
s = Integer.toString(factorial);
}
return s;
}
}
package com.codegym.task.task15.task1531;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;
/*
Factorial
*/
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
int input = Integer.parseInt(reader.readLine());
reader.close();
System.out.println(factorial(input));
}
public static String factorial(int n) {
//write your code here
String s = "";
if (n <0)
s = "0! = 1";
else if(n == 0)
s = "1";
else {
int factorial = 1;
for (int i = 1; i <= n; i++) {
factorial = factorial * i;
}
s = Integer.toString(factorial);
}
return s;
}
}