C#——创建Windows应用程序,统计从键盘输入一行字符串中,大写字母个数,小写字母的个数并输出。使用do while循环

首先设计如下界面:

C#——创建Windows应用程序,统计从键盘输入一行字符串中,大写字母个数,小写字母的个数并输出。使用do while循环

编写如下代码:

 

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

 

namespace tt

{

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

        }

 

        private void button1_Click(object sender, EventArgs e)

        {

            int i = 0;

            int numberBig=0;

            int numberLittle=0;

            do

            {

                char c=textBox1 .Text [i++];

                if(c>='A'&c<='Z')

                {

                    numberBig ++;

                }

                if(c>='a'&c<='z')

                {

                    numberLittle++;

                }

            }while (i!=textBox1 .TextLength);

            label2.Text = "大写字母个数为:"+numberBig+"\n小写字符个数:"+numberLittle;

        }

    }

}

 

运行结果:

C#——创建Windows应用程序,统计从键盘输入一行字符串中,大写字母个数,小写字母的个数并输出。使用do while循环