using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//运用所学知识,输入5个字符,将其倒序打印出来
namespace ans2
{
class Program
{
static void Main(string[] args)
{
string s = Console.ReadLine();
int len = s.Length;
while(len != 5)
{
s = Console.ReadLine();
len = s.Length;
}
for (int i =len-1; i>=0; i--)
{
Console.Write("{0}",s[i]);
}
Console.WriteLine();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//运用所学知识,输入5个字符,将其倒序打印出来
namespace ans2
{
class Program
{
static void Main(string[] args)
{
string s;
int len;
while(true)
{
s = Console.ReadLine();
len = s.Length;
if (len == 5)
break;
}
for (int i =len-1; i>=0; i--)
{
Console.Write("{0}",s[i]);
}
Console.WriteLine();
}
}
}
推荐答案
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
char[] ch = new char[5];
Console.WriteLine("请输入字符(用回车间隔):");
for (int i = 0; i < 5; i++)
{
ch[i] = Convert.ToChar(Console.ReadLine());
//ch[i] = Char.Parse(Console.ReadLine());这一句也可以转换为字符
}
Console.Write("倒序输出为:");
for (int i = ch.Length - 1; i >= 0; i--)
{
Console.Write(ch[i]);
}
Console.ReadLine();
}
}
}