본문 바로가기

ETC Programmings

거꾸로 해도 같은지 검사하는 프로그램(C# 버젼)

336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication2
{
    class Test
    {
        private String str;

        public Test(String str)
        {
            this.str = str;
        }
        public Test()
        {
        }
        public void setStr(String str)
        {
            this.str = str;
        }
        public void setStr()
        {
            Console.WriteLine("검사할 문자열을 입력해줘요");
            this.str = Console.ReadLine();
        }
        public void run()
        {
            if (str == null)
                setStr();
            Console.WriteLine("검사하실 문자열은 " + str + " 입니다.");
            Console.WriteLine(checkReverseStr(str));
        }
        public bool checkReverseStr(String str)
        {
            return str.Equals(getReverseStr(str));
        }
        public String getReverseStr(String str)
        {
            String reversedString = "";
            for (int i = str.Length - 1; i >= 0; i--)
                reversedString += str.Substring(i, 1);
            return reversedString;
        }
        static void Main(string[] args)
        {
            Test t = new Test();
            t.run();
                                       
        }
    }
}

워.. -ㅅ-... 생각보다 킹왕짱 어려움 ㅠㅠ