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 统计用户输入的一串数字中每个数字出现的次数
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string j = textBox1.Text;
int num1 = 0, num2 = 0, num3 = 0, num4 = 0, num5 = 0, num6 = 0, num7 = 0, num8 = 0, num9 = 0, num0 = 0;
for (int i = 0; i < j.Length; i++)
{
switch (textBox1.Text.Substring(i,1))
{
case "1":
num1++;
break;
case "2":
num2++;
break;
case "3":
num3++;
break;
case "4":
num4++;
break;
case "5":
num5++;
break;
case "6":
num6++;
break;
case "7":
num7++;
break;
case "8":
num8++;
break;
case "9":
num9++;
break;
default:
num0++;
break;
}
}
MessageBox.Show("1:" + num1 +"个 "+ " 2:" + num2 +"个 "+ " 3:" + num3 +"个 "+ " 4:" + num4 +"个 "+ " 5:" + num5+"个 " + " 6:" + num6+"个 " + " 7:" + num7 +"个 "+ " 8:" + num8 +"个 "+ " 9:" + num9+"个 " + " 0:" + num0 + "个");
}
}
}