本文主要是介绍c#:输入5个字符,将其倒序打印出来,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
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();
}
}
}
这篇关于c#:输入5个字符,将其倒序打印出来的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!