首页 > 试题广场 > 编写一个控制台应用程序,要求用户输入 5 个大写字母,如果用
[问答题]

编写一个控制台应用程序,要求用户输入 5 个大写字母,如果用户输入的信息不满足要求,提示帮助信息并要求重新输入。

int
发表于 2020-03-17 13:36:31 回复(0)

class Program
    {
        static void Main(String[] args)
        {
            while (true)
            {
                Console.WriteLine("pleace input 5 uppercase letters:");
                string s = Console.ReadLine();
                char[] c = s.ToCharArray();
                bool flag = true;
                if(c.Length == 5)
                {
                    for(int i = 0; i< 5; i++)
                    {
                        if ((int)c[i] < 65 || (int)c[i] > 90)
                        {
                            flag = false;
                            Console.WriteLine("Your input does not meet the requirements, please re-enter!");
                            break;
                        }
                    }
                }
                else
                {
                    flag = false;
                    Console.WriteLine("Your input does not meet the requirements, please re-enter!");
                }

                if (flag)
                {
                    Console.WriteLine("ok!");
                    break;
                }
            }
            Console.ReadKey();
        }
    }

发表于 2019-09-20 10:21:05 回复(0)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace demo5
{
    class Program
    {
        static void Main(string[] args)
        {
            char m1 = 'A';
            char m2 = 'Z';
            string allch = "";
            Console.WriteLine("{0},{1}",(int)m1,(int)m2);
            Console.WriteLine("Please input five uppercase letters:");
            for (int i = 0; i < 5; i++)
            {
                char ch = char.Parse(Console.ReadLine());

                if ((int)ch < 65 || (int)ch > 90)
                {
                    Console.WriteLine("Input error!Please input right character");
                    i--;
                    continue;
                }
                allch += ch.ToString();
            }
            Console.WriteLine("Finish input:{0}",allch);
            Console.ReadKey();
        }
    }
}
发表于 2018-11-20 10:16:47 回复(0)