C# 简单实现输入位数分离(初学者必备)

利用基础语法实现位数分离

初学者推荐观看

收货一些思路

以下是相关代码

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _005_实现位数分离
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.Write("请输入数字:");
            int number = Convert.ToInt32(Console.ReadLine());
            int copy = number;
            //用一个除法逻辑判断用户输入数字长度
            int count = 1;     // 因为我判断逻辑设计是会修改值的,这会导致最后一次进不去,因此我将变量初始值设置为1
            while((copy /= 10) !=0)
            { 
                count++;
            }
            // 获得数字的长度

            // 格式化数字结果
            string result = "";
            // 打印表头
            string money = "";
            // 格式化表头
            string[] arr = { "个", "十", "百", "千", "万", "十万", "百位", "千万", "亿" };
            for (int i = 0; i<count; i++)
            {
                money += arr[i];
                money += "\t";
                int temp = number % 10;
                result += temp;
                result += "\t";
                number /= 10;
            }
          
            Console.WriteLine("从个位开始分离的数据集是:\n" + money +"\n" +result);

        }
    }
}

  • 9
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值