Objectivo
Cree un programa en C# para pedirle al usuario un símbolo y responda si es una vocal mayúscula, una vocal minúscula, un dígito o cualquier otro símbolo, usando "if".
Ejemplo Ejercicio C#
Mostrar Código C#
using System; // Import the System namespace to use basic classes like Console
class Program // Define the main class of the program
{
static void Main() // The entry point of the program
{
// Ask the user to enter a symbol
Console.Write("Enter a symbol: "); // Display prompt for the symbol input
char symbol = Console.ReadKey().KeyChar; // Read the symbol entered by the user
// Check if the symbol is an uppercase vowel
if ("AEIOU".IndexOf(symbol) >= 0) // If the symbol is in the string "AEIOU"
{
Console.WriteLine("\nThe symbol is an uppercase vowel."); // Display message for uppercase vowel
}
// Check if the symbol is a lowercase vowel
else if ("aeiou".IndexOf(symbol) >= 0) // If the symbol is in the string "aeiou"
{
Console.WriteLine("\nThe symbol is a lowercase vowel."); // Display message for lowercase vowel
}
// Check if the symbol is a digit
else if (Char.IsDigit(symbol)) // If the symbol is a digit
{
Console.WriteLine("\nThe symbol is a digit."); // Display message for digit
}
// If none of the above conditions are true, it's any other symbol
else
{
Console.WriteLine("\nThe symbol is neither a vowel nor a digit."); // Display message for other symbols
}
}
}
Salida
Case 1:
Enter a symbol: A
The symbol is an uppercase vowel.
Case 2:
Enter a symbol: e
The symbol is a lowercase vowel.
Case 3:
Enter a symbol: 3
The symbol is a digit.
Case 4:
Enter a symbol: #
The symbol is neither a vowel nor a digit.
Código de Ejemplo Copiado!
Comparte este Ejercicio C# Sharp