• 【专题】取得一个数各个位的值


    class Program
        {
            static void Main(string[] args)
            {
                /*
                int i = 365;
                //就是三位数
    
                int sheng = 365;
                int ge = sheng % 10;
    
               // int ge = i % 10;
                Console.WriteLine("个位"+ge);
                //int sheng = i / 10;//36
                sheng = sheng / 10;
                Console.WriteLine("剩" + sheng);
    
                int shi = sheng % 10;
                Console.WriteLine("十位" + shi);
    
                sheng = sheng / 10;
                Console.WriteLine("剩" + sheng);
    
                int bai = sheng % 10;
                Console.WriteLine("百位"+bai);
                sheng = sheng / 10;
                Console.WriteLine("剩" + sheng);
                */
    
                /*
                int n = 3721886;
                int sheng = n;
                while (sheng != 0)
                {
                    int wei = sheng % 10;
                    Console.WriteLine(wei);
    
                    sheng = sheng / 10;
                }*/
    
                int n = 3721886;
                string s = n.ToString();//项目中哪个方便用哪个。面试的时候尽量不用.net内置的方法
                for (int i = 0; i < s.Length; i++)
                {
                    char ch = s[i];
                    int iWei = ch-'0';//'1'→1
                    //Console.WriteLine(ch);
                    Console.WriteLine(iWei);
                }
                Console.ReadKey();
            }
        }
  • 相关阅读:
    实习日记7.28
    实习日记7.27
    实习总结(第三周)
    实习日记7.26
    实习日记7.25
    实习总结(第二周)
    实习总结(第一周)
    实习日记7.22
    实习日记7.21
    5月4下
  • 原文地址:https://www.cnblogs.com/lolitagis02/p/8094685.html
Copyright © 2020-2023  润新知