Factorial in Dart

Published on 04 October 2025 (Updated: 04 October 2025)

Welcome to the Factorial in Dart page! Here, you'll find the source code for this program as well as a description of how the program works.

Current Solution

// Issue 4969
void main(List<String> args){
  const String error_message = "Usage: please input a non-negative integer";
  try{

    int factorial = 1;
    int num_needed = int.parse(args[0]);
    if (num_needed.isNegative == true){
      print(error_message);
    }
    else{
      for (int i_index = 1; i_index <= num_needed; i_index ++){
        factorial *= i_index;
      }
      print(factorial.toString());
    }

  }
  catch(e){
    print(error_message);
  }
}

Factorial in Dart was written by:

If you see anything you'd like to change or update, please consider contributing.

How to Implement the Solution

No 'How to Implement the Solution' section available. Please consider contributing.

How to Run the Solution

No 'How to Run the Solution' section available. Please consider contributing.