您的位置:首页 > 编程语言 > C#

C#打印水仙花数(3位数)

2014-11-25 11:58 288 查看
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ShuiXianHua
{
    //打印水仙花数
    class ShuiXianHua_1
    {
        int i;
        int j;
        int k;
        //int number;
        public void checkNum()
        {
            Console.Write("打印水仙花数(三位数):");

            for (int num = 100; num < 1000; num++)
            {
                i = num / 100;        //百位数字
                j = num % 100 / 10;  //十位数字
                k = num % 10;        //个位数字
                if (i * i * i + j * j * j + k * k * k == num)
                    Console.Write(":{0,5}", num);
            }
            Console.WriteLine();
        }
        
    }
    class Program
    {
        static void Main(string[] args)
        {
            ShuiXianHua_1 method1 = new ShuiXianHua_1();
            method1.checkNum();
            Console.ReadKey();
        }
    }
}
<span style="font-family:SimHei;font-size:18px;">方法还有很多,后续会进行说明和贴上代码块。</span>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐