0

I am trying to solve the CodeChef problem "Small factorials". The task is to calculate the factorial of given numbers. I have the following code, which I have checked so many times. For me it gives right output, but when I try to upload it to CodeChef it gives error Wrong Answer.

import java.util.Scanner;

class SmallFactorial {
    public static void main(String[]args){
        Scanner sc = new Scanner(System.in);
        int iterations = sc.nextInt();
        int[] myArray = new int[iterations];
        int result = 1;
        for(int b = 0; b < iterations; b++) {
            int n = sc.nextInt();
            if (n >= 1 && n <= 100) {
                for (int i = 1; i <= n; i++) {
                    result = result * i;
                }
                myArray[b] = result;
                result = 1;
            }
        }
        for(int z = 0; z < myArray.length; z++){
            System.out.println(myArray[z]);
        }
        sc.close();
    }
}
Tom
  • 16,842
  • 17
  • 45
  • 54
Tano
  • 609
  • 8
  • 23

2 Answers2

0

I can't see some fatal misstake but there can be problem with if condition because 0! =1 and you don't solve this one Or you are giving wrong output syntax for the program that control this

Angen
  • 400
  • 2
  • 10
0

The code works fine on my end, but for small integers only.

Do take note that the max int value in Java is 2,147,483,647, and so some values may not evaluate to what you think they would.

Also this link might be useful.

Aaa
  • 134
  • 1
  • 8