CLASE EJECUTORA
using System;
namespace Enunciado_3
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("*****FRASE PALINDROMA******");
Console.WriteLine("INGRESE UNA FRASE: ");
string frase = Console.ReadLine();
Palindroma ObjPalind = new Palindroma(frase);
Console.ReadKey();
}
}
}
CLASE CONVENCIONAL
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Enunciado_3
{
class Palindroma
{
private string frase;
private string frasepalind;
private string frasesinespacios;
public Palindroma()
{
this.frase = null;
this.frasesinespacios = null;
this.frasepalind = null;
}
public Palindroma(string cadena)
{
frase = cadena;
frasesinespacios = frase.Replace(" ", "");
for (int i = frasesinespacios.Length - 1; i >= 0; i--)
{
frasepalind = frasepalind + frasesinespacios.Substring(i, 1);
}
Console.WriteLine(frasesinespacios);
Console.WriteLine(frasepalind);
if (frasesinespacios == frasepalind)
{
Console.WriteLine("VERDADERO");
}
else
Console.WriteLine("FALSO");
}
}
}
No hay comentarios:
Publicar un comentario