统计用户输入的一串数字中每个数字出现的次数

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 + "个");

 }

 }

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值