-3
public static void Main(string[] args)
{
    int n = Convert.ToInt32(Console.ReadLine());
    int[] array = new int[n];
    for (int i = 0; i < n; i++)
    {
        array[i] = Int32.Parse(Console.ReadLine());
    }
    var arrays = ReverseArray(array);
    Console.WriteLine(String.Join(' ', arrays));
}

In the main method, array\[i\] = Int32.Parse(Console.ReadLine()); it's not reading the proper input and getting the runtime exception as:

Unhandled exception. System.FormatException: Input string was not in a correct format.
at System.Number.ThrowOverflowOrFormatException(ParsingStatus status, TypeCode type)
at System.Int32.Parse(String s)
at Solution.Main(String\[\] args) in /tmp/submission/20230817/19/08/hackerrank-824af6b450e18d4281237c38cf1b9194/code/Solution.cs:line 36
Aborted (core dumped)

Trying to read the user input integer array in C#. But getting the runtime exception as:

System.FormatException: Input string was not in a correct format.
at System.Number.ThrowOverflowOrFormatException(ParsingStatus status, TypeCode type)
at System.Int32.Parse(String s)
at Solution.Main(String\[\] args) in /tmp/submission/20230817/19/08/hackerrank-824af6b450e18d4281237c38cf1b9194/code/Solution.cs:line 36
Aborted (core dumped).

I have spent more than 5-6 hrs but couldn't find the solution for it. Please suggest to me the correct answer.

LW001
  • 2,452
  • 6
  • 27
  • 36

0 Answers0