Ejercicio
Parámetros De Main, Reverso
Objectivo
Cree un programa llamado "reverse", que reciba varias palabras en la línea de comandos y las muestre en orden inverso, como en este ejemplo:
invertir uno dos tres
Tres, dos, uno
Ejemplo Ejercicio C#
Mostrar Código C#
// Importing the System namespace to access basic system functions
using System;
class Program
{
// Main method where the program starts
public static void Main(string[] args)
{
// Check if there are any arguments passed from the command line
if (args.Length == 0)
{
Console.WriteLine("No words provided."); // If no words are provided, print a message
return; // Exit the program
}
// Loop through the arguments in reverse order and print each word
for (int i = args.Length - 1; i >= 0; i--)
{
Console.Write(args[i] + " "); // Print each word followed by a space
}
Console.WriteLine(); // Add a new line at the end
}
}
Salida
-- Case 1: Execution with no arguments
dotnet run
No words provided.
-- Case 2: Execution with multiple arguments
dotnet run Hello World CSharp
CSharp World Hello
-- Case 3: Execution with a single argument
dotnet run Welcome
Welcome
Código de Ejemplo Copiado!
Comparte este Ejercicio C# Sharp