C#中的一个控制台程序用户输入5个大写字母如果输入不满足要求提示
用户输入5个大写字母 如果输入不满足要求 提示并重新输入 最后输出
using ; using System.Collections.Generic; using System.Text; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { bool flag; do { flag = true; Console.Write("请输入五位数大写字母:"); string str = Console.ReadLine(); if (str.Length != 5) { Console.WriteLine("字符个数错误"); flag = false; continue; } foreach (char ch in str) { if (ch < 'A' || ch > 'Z') { Console.WriteLine("字符输入错误"); flag = false; break; } } }while(flag==false); Console.WriteLine("输入正确"); } } }